Downloading a Google Slides presentation as PowerPoint doc using Google Apps Script?

[亡魂溺海] 提交于 2019-12-01 23:27:00

How about this modification?

Modification point:

  • response.getContent() returns byte array. So please use response.getBlob().

Modified script:

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));
}

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 = 'https://docs.google.com/presentation/d/' + fileId + '/export/pptx?access_token=' + ScriptApp.getOAuthToken();
  • DriveApp.createFile() creates a file on root folder as the default.

References:

New_2_Code

As mentioned by tehhowch, you could get the Google Slide file from your Drive and get it as a .pptx. (Not sure of mime type.)

File#getAs:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!