使用Google Apps脚本下载PowerPoint文档形式的Google幻灯片演示文稿?

编程入门 行业动态 更新时间:2024-10-11 23:18:45
本文介绍了使用Google Apps脚本下载PowerPoint文档形式的Google幻灯片演示文稿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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().
function convertFileToPptx() { var fileId = "1Zc4-yFoUYONXSLleV_IaFRlNk6flRKUuAw8M36VZe-4"; var outputFileName = "test2.pptx"; var url = 'docs.google/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 = 'docs.google/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
    • Note:

      • 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()

更多推荐

使用Google Apps脚本下载PowerPoint文档形式的Google幻灯片演示文稿?

本文发布于:2023-10-31 10:45:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   脚本   演示文稿   形式   文档

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!