【发布时间】:2017-08-10 18:50:10
【问题描述】:
我想使用 Google Apps 脚本将原生 Google 电子表格/文档/绘图/演示文件导出到同一文件夹中的另一种格式。 我启用了Advanced Drive Service,并查看了Open and Convert Google Docs in your app的说明。
希望我可以使用Export 获得File,然后我可以使用Insert 保存/重命名它。
尝试实现以下目标:
var file = {fileId: "1yDe...lD2U",
folderId: "0B_...hZ1k",
mimetype:"application/vnd.google-apps.document",
targetMimetype:"application/pdf",
targetName:"my converted document"}
var newFile = Drive.Files.export(file.fileId, file.targetMimetype)
// results in error message:
// "Export requires alt=media to download the exported content."
// I am sure the above is incomplete, but unsure how to actually
// save the exported file, in the correct location, with correct filename
更新:将 alt=media 添加到调用 (var newFile = Drive.Files.export(file.fileId, file.targetMimetype, {alt: "media"})) 时,脚本会以错误代码 200 退出并在错误消息中显示 PDF 内容。类似于issue 6573。
更新:这可能不够清楚,我想转换/转换Advanced Drive 页面中列出的所有格式,而不仅仅是 PDF。 DriveApp getAs 文档指出 DriveApp 可以大部分转换为 PDF 和图像。因此,重点是使用 Advanced Drive 而不是 DriveApp。
【问题讨论】:
-
出于任何原因,您不能使用应用脚本原生函数,例如:var blob = DriveApp.getFileById(file.fileId).getAs('application/pdf') 和 DriveApp.getFolderById(file.folderId)。 createFile(blob) 来创建你的 newPdfFile?
-
好点。应该适用于 PDF 导出。不过,我需要转换为“在您的应用中打开和转换 Google 文档”中列出的所有格式。 developers.google.com/apps-script/reference/drive/… 声明:要转换为的 MIME 类型。对于大多数 blob,“application/pdf”是唯一有效的选项。对于 BMP、GIF、JPEG 或 PNG 格式的图像,“image/bmp”、“image/gif”、“image/jpeg”或“image/png”中的任何一个都有效。
标签: google-apps-script google-drive-api