问题描述
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);
}
}
它返回一个错误:
第二编辑
根据评论中的另一个建议,我尝试通过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('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的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 useresponse.getBlob()
.
function convertFileToPptx() {
var fileId = "1Zc4-yFoUYONXSLleV_IaFRlNk6flRKUuAw8M36VZe-4";
var outputFileName = "test2.pptx";
var url = 'https://docs.google.com/presentation/d/' + fileId + '/export/pptx';
var rootFolder = DriveApp.getRootFolder();
var response = UrlFetchApp.fetch(url);
var blobPptx = response.getBlob();
var result = rootFolder.createFile(blobPptx.setName(outputFileName));
}
注意:
- 如果要在Google云端硬盘中转换未发布的Google幻灯片,请使用访问令牌.那时,请按以下方式修改
url
.-
var url = 'https://docs.google.com/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 = 'https://docs.google.com/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
- Class HTTPResponse
- getOAuthToken()
这篇关于使用Google Apps脚本下载PowerPoint文档形式的Google幻灯片演示文稿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
Note:
-