转换谷歌Doc到Docx使用谷歌脚本



是否可以使用Google Script以编程方式将Google文档转换为Word docx文件?

应该可以了

function myFunction() {
  var token = ScriptApp.getOAuthToken();
  //Make sure to replace the correct file Id
  // Fetch the docx blob
  var blb = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/export/Export?id=<ID_of_Google_Document>&exportFormat=docx', 
                              {
                                headers : {
                                  Authorization : 'Bearer '+token
                                }
                              }).getBlob();
  //Create file in Google Drive
  var file = DriveApp.createFile(blb).setName('<name_of_exported_file>.docx');
  //Put the file in a drive folder
  DriveApp.getFolderById('<FOLDER_ID>').addFile(file);
}

在问题跟踪器上引用此条目…

你可以转换谷歌文档到docx今天使用驱动器先进的服务:

https://developers.google.com/apps-script/advanced/drive

下面是一个小例子:

function convertToDocx(documentId) {
  var file = Drive.Files.get(documentId);
  var url = file.exportLinks['application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
  var oauthToken = ScriptApp.getOAuthToken();
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' + oauthToken
    }
  });
  return response.getBlob();
}

相关内容

  • 没有找到相关文章