将文件夹中所有可用的 xls 文件转换为“Google 文档电子表格”?

mio*_*odf 5 google-sheets google-apps-script google-drive-api

实现此目的的基本方法是将文件上传到 Google 云端硬盘时打开转换。

\n\n

另一种方法是选择文件夹中的xls文件,然后手动逐个转换。

\n\n

但是,如果一个文件夹中已经上传了许多 xls 文件,则使用 Google Apps 脚本转换它们可能比再次重新上传文件更快。

\n\n

就我而言:

\n\n
    \n
  • 转换后,我需要删除 xls 文件
  • \n
  • 所有 xls 文件均低于限制:“上传的转换为 Google 电子表格格式的电子表格文件\xe2\x80\x99 不能大于 100 MB,并且每张工作表的单元格数不得超过 400,000 个且列不得超过 256 列。”\n https ://support.google.com/drive/answer/37603?hl=zh-CN
  • \n
\n\n

提前致谢;)

\n

Ser*_*sas 5

你应该使用高级驱动服务文件更新

该服务必须在使用前启用,但文档非常清楚。


编辑(根据您的评论)

(对不起,耽误了这么久,我忘记了这篇文章)

此代码会将驱动器中的每个 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
      });
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述