执行此操作的基本方法是在将文件上传到 Google 云端硬盘时开启转换。
另一种方法是选择文件夹中的xls文件,并手动对其进行转换。
但是,如果一个文件夹中已经上传了许多 xls 文件,则使用 Google Apps 脚本转换它们可能比重新上传文件更快。
就我而言:
https://support.google.com/drive/answer/37603?hl=en
提前致谢;)
最佳答案
您应该使用 Advanced Drive Service , file update
此服务必须在使用前启用,但文档非常清楚。
编辑(按照您的意见)
(抱歉耽误了这么久,我忘记了这个帖子)
此代码会将您驱动器中的每个 XLS 文件转换为 Google 电子表格格式(只要它们的名称具有 .xls 扩展名)
您必须授权 Drive 扩展资源 + API 控制台(按照资源/高级服务菜单中的说明进行操作,参见下图)
function importXLS(){
var files = DriveApp.searchFiles('title contains ".xls"');// you can also use a folder as starting point and get the files in that folder... use only DriveApp method here.
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
}
file = Drive.Files.insert(newFile, xBlob, {
convert: true
});
}
}
}
关于google-apps-script - 将文件夹中所有可用的 xls 文件转换为 "Google Doc Spreadsheets"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25368143/