Google幻灯片的GUI提供了将GSlides演示文稿下载为Powerpoint(myFile.pptx)的功能.我在Google Apps脚本文档中找不到等效项-是否有任何指针?
The GUI of Google Slides offers to download a GSlides presentation as a Powerpoint (myFile.pptx). I could not find the equivalent in the Google Apps Script documentation - any pointer?
编辑
感谢评论和答案,我尝试了以下代码段:
Thanks to comments and answers, I tried this snippet:
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转换为 application/vnd.openxmlformats-officedocument.presentationml.presentation 不支持. (第7行,文件代码")
Converting from application/vnd.google-apps.presentation to application/vnd.openxmlformats-officedocument.presentationml.presentation is not supported. (line 7, file "Code")
第二编辑
根据评论中的另一个建议,我尝试通过Google App Script进行http调用,该调用将gslides直接转换为pptx,没有大小限制.它在G盘上生成一个文件,但该文件已损坏/不可读. GAS脚本:
As per another suggestion in comments, I tried to make an http call from Google App Script, that would directly convert the gslides into pptx, without size limit. It produces a file on G Drive, but this file is corrupted / unreadable. The GAS script:
function convertFileToPptx() { // Converts a public Google Slide file into a pptx var rootFolder = DriveApp.getRootFolder(); var response = UrlFetchApp.fetch('docs.google/presentation/d/1Zc4-yFoUYONXSLleV_IaFRlNk6flRKUuAw8M36VZe-4/export/pptx'); var blobPptx = response.getContent(); var result = rootFolder.createFile('test2.pptx',blobPptx,MimeType.MICROSOFT_POWERPOINT); }注意:
- 我得到了pptx的mime类型在这里
- 使用mime类型'pptx'会返回相同的错误消息
- I got the mime type for pptx here
- using the mime type 'pptx' returns the same error message
此修改如何?
- response.getContent()返回字节数组.因此,请使用response.getBlob().
- response.getContent() returns byte array. So please use response.getBlob().
注意:
- 如果要在Google云端硬盘中转换未发布的Google幻灯片,请使用访问令牌.那时,请按以下方式修改url.
- var url = 'docs.google/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
- If you want to convert Google Slides, which are not published, in your Google Drive, please use access token. At that time please modify url as follows.
- var url = 'docs.google/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
- 类HTTPResponse
- getOAuthToken()
- Class HTTPResponse
- getOAuthToken()
Note:
更多推荐
使用Google Apps脚本下载PowerPoint文档形式的Google幻灯片演示文稿?
发布评论