【发布时间】:2018-09-27 11:59:07
【问题描述】:
Google 幻灯片的 GUI 提供以 Powerpoint (myFile.pptx) 形式下载 GSlides 演示文稿。我在 Google Apps 脚本文档中找不到对应的 - 任何指针?
编辑
感谢cmets和答案,我尝试了这个sn-p:
function testFileOps() {
// Converts the file named 'Synthese' (which happens to be a Google Slide doc) into a pptx
var files = DriveApp.getFilesByName('Synthese');
var rootFolder = DriveApp.getRootFolder();
while (files.hasNext()) {
var file = files.next();
var blobPptx = file.getBlob().getAs('application/vnd.openxmlformats-officedocument.presentationml.presentation');
var result = rootFolder.createFile(blobPptx);
}
}
它返回一个错误:
从 application/vnd.google-apps.presentation 转换为 应用程序/vnd.openxmlformats-officedocument.presentationml.presentation 不支持。 (第 7 行,文件“代码”)
第二次编辑
根据 cmets 中的另一个建议,我尝试从 Google App Script 进行 http 调用,直接将 gslides 转换为 pptx,没有大小限制。它会在 G Drive 上生成一个文件,但该文件已损坏/无法读取。 GAS 脚本:
function convertFileToPptx() {
// Converts a public Google Slide file into a pptx
var rootFolder = DriveApp.getRootFolder();
var response = UrlFetchApp.fetch('https://docs.google.com/presentation/d/1Zc4-yFoUYONXSLleV_IaFRlNk6flRKUuAw8M36VZe-4/export/pptx');
var blobPptx = response.getContent();
var result = rootFolder.createFile('test2.pptx',blobPptx,MimeType.MICROSOFT_POWERPOINT);
}
注意事项:
- 我得到了 pptx here 的 mime 类型
- 使用 mime 类型
'pptx'返回相同的错误消息
【问题讨论】:
-
将文件导出为给定的 mimetype。请注意,由于 Apps 脚本不会在您的浏览器中运行,因此您需要将其作为 web 应用程序的一部分(返回
downloadAsFile)或在 Google 云端硬盘中创建工作文件。 -
非常感谢!关于哪一行 GAS 将进行导出的任何指针?我在在线文档中找不到?
-
您需要 Drive Service 或 Drive API(高级服务)。
-
用代码 sn-p 编辑了问题。是否符合您推荐的方法?
-
没有大小限制(目前为 10 Mb)将 Google 幻灯片导出到 pptx 的答案:stackoverflow.com/a/50680468/555121
标签: google-apps-script google-slides-api google-slides