【问题标题】:Setting Document Type from App Script从 App 脚本设置文档类型
【发布时间】:2015-03-30 13:32:24
【问题描述】:

我每周都会收到一个通过电子邮件发送的压缩 csv 文件,并编写了一个谷歌应用脚​​本来从电子邮件中获取文件并保存到驱动器:

   // unzip it
   var unzipblob = Utilities.unzip(att[z]);

   // Create with a unique filename using date of email
   var newName = 'provider_stats-' + Utilities.formatDate(date, 'GMT', 'yyyy-MM-dd') + '.csv';

   // Save the first file (there's only one) in the zip
   file = folder.createFile(newName, unzipblob[0].getDataAsString());
   file.setDescription(newName);

这工作正常,但我注意到在我保存它的驱动器文件夹中,它似乎与我手动执行的文档类型不同。当我右键单击时,其他选项提供“在 Google 表格中打开”作为选项,但不是从脚本中保存的选项。

知道如何设置文档类型或格式,以便可以直接在 Google 表格中打开吗?

我的下一步是直接保存为 Google 表格,因此提前提供的任何帮助也将被视为答案!

【问题讨论】:

    标签: csv google-apps-script google-drive-api google-sheets


    【解决方案1】:

    找到了,比我想象的要容易得多!

    只需使用 Drive Folder 方法将文件的 MIME 类型设置为“text/csv”即可:

    file = folder.createFile(newName, unzipblob[0].getDataAsString(), "text/csv");

    那么GSheets就是一个右键选项!

    【讨论】:

    • 请注意,它很容易保存为新工作表,问题也会消失。
    猜你喜欢
    • 1970-01-01
    • 2010-11-01
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 2012-05-17
    相关资源
    最近更新 更多