gpt4 book ai didi

google-apps-script - 将文件夹中所有可用的 xls 文件转换为 "Google Doc Spreadsheets"?

转载 作者:行者123 更新时间:2023-12-03 23:25:20 25 4
gpt4 key购买 nike

执行此操作的基本方法是在将文件上传到 Google 云端硬盘时开启转换。

另一种方法是选择文件夹中的xls文件,并手动对其进行转换。

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

就我而言:

  • 转换后,我需要删除 xls 文件
  • 所有 xls 文件都低于限制:“上传的转换为 Google 电子表格格式的电子表格文件不能大于 100 MB,并且每张表格需要少于 400,000 个单元格和 256 列。”
    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
    });
    }
    }
    }

    enter image description here

    关于google-apps-script - 将文件夹中所有可用的 xls 文件转换为 "Google Doc Spreadsheets"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25368143/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com