我正在尝试创建一个脚本,该脚本会将文件夹中的xls文档转换为工作表版本,然后删除xls版本。该脚本可以工作,但是由于该文件夹中有很多xls文件,因此我认为它正在超时,因为它会抛出:“很抱歉,发生服务器错误。请稍候,然后重试。(第6行,我开始运行它后,文件“转换XLS”)“错误。有没有办法在服务器不超时的情况下执行此操作?
function convertXLS() {
var folder = DriveApp.getFolderById('File_ID');
var files = folder.getFilesByType(MimeType.micrOSOFT_EXCEL_LEGACY);
while (files.hasnext()) {
var file = files.next();
Drive.Files.copy({},file.getId(),{convert: true});
}
// while (files.hasnext()) {
// Drive.Files.remove( file.getId());
//}
}
更新:
所以我将代码重新配置为:
function importXLS(){
var folder = DriveApp.getFolderById('File_ID');// you can also use a folder as starting point and get the files in that folder... use only DriveApp method here.
var files = folder.getFilesByType(MimeType.micrOSOFT_EXCEL_LEGACY);
while(files.hasnext()){
var xFile = files.next();
var name = xFile.getName();
if (name.indexOf('.xls')>-1){ // this check is not necessaey here because I get the files with a search but I left it in case you get the files differently...
var ID = xFile.getId();
var xBlob = xFile.getBlob();
var newFile = { title : name+'_converted',key : ID,'parents':[{"id":"File_ID"}]
}
file = Drive.Files.insert(newFile,xBlob,{
convert: true,});
}
}
}
但是现在它给了我这个错误,运行大约两分钟后,“对drive.files.insert的API调用失败,错误:内部错误(第14行,文件“转换XLS”)。我不知道该怎么办:(