首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >google sheets to zip using apps script

google sheets to zip using apps script
EN

Stack Overflow用户
提问于 2019-03-13 23:23:08
回答 1查看 76关注 0票数 0

我正在尝试使用谷歌应用程序脚本中的以下代码从google sheets制作zip文件:

var blobs = [];

function myFunction(){
   var file = DriveApp.getFileById("fileId");
   var blobObject = file.getBlob();
   var blobObject1 = file.getBlob().setContentType("application/vnd.google-apps.spreadsheet").setName("blob1.xlsx");
   var blobObject2 = file.getBlob().setContentType('application/vnd.ms-excel').setName("blob2.xlsx");
   var blobObject3 = file.getBlob().setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").setName("blob3.xlsx");

   blobs.push(blobObject)
   blobs.push(blobObject1)
   blobs.push(blobObject2)
   blobs.push(blobObject3)

   Logger.log(file.getMimeType());    // output : application/vnd.google-apps.spreadsheet
   Logger.log(blobObject.getContentType())   // output : application/pdf

   Logger.log(blobObject1.getContentType()) // output : application/vnd.google-apps.spreadsheet
   Logger.log(blobObject2.getContentType()) // output : application/vnd.ms-excel
   Logger.log(blobObject3.getContentType()) // output : application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


   var timestamp = new Date().toISOString().split("T")[0];
   var zip = Utilities.zip(blobs, "FolderName"+timestamp+".zip");
   var folder = DriveApp.getFolderById("FolderId");
   folder.createFile(zip);  

}

我可以得到4个文件的压缩文件。1个文件为.xlsx格式,3个为pdf格式。

但不幸的是,所有的.xlsx文件都被损坏了。

打开.xlsx时出现以下错误:

Excel cannot open the file because the file format or file extension is not valid.
Verify that the file has not been corrupted and that the file extension matches the format of the file.

请建议我如何才能达到理想的效果。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55145461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档