Google幻灯片的GUI可以下载GSlides演示文稿作为Powerpoint(myFile.pptx)。我在Google Apps脚本文档中找不到等效项-有指针吗?
编辑
感谢评论和答案,我尝试了以下代码段:
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行,文件“代码”)
第二编辑
根据评论中的另一个建议,我尝试通过Google App Script进行http调用,该调用将gslides直接转换为pptx,没有大小限制。它在G盘上生成一个文件,但该文件已损坏/不可读。 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'
会返回相同的错误消息答案 0 :(得分:1)
此修改如何?
response.getContent()
返回字节数组。因此,请使用response.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));
}
url
。
var url = 'https://docs.google.com/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
DriveApp.createFile()
在根文件夹上创建一个默认文件。答案 1 :(得分:0)
如tehhowch所述,您可以从云端硬盘中获取Google幻灯片文件,并将其作为.pptx
来获取。 (不确定mime类型。)
答案 2 :(得分:0)
我添加了所有带有令牌部分和特定文件夹的修改
function convertFileToPptx() {
var fileId = "Your File ID";
var outputFileName = "name.pptx";
var url = 'https://docs.google.com/presentation/d/' + fileId + '/export/pptx';
//var rootFolder = DriveApp.getRootFolder();
var rootFolder = DriveApp.getFolderById("Your Folder ID")
var params = {method:"GET", headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
var response = UrlFetchApp.fetch(url,params);
var blobPptx = response.getBlob();
var result = rootFolder.createFile(blobPptx.setName(outputFileName));
}