首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google Script将Google Doc转换为Docx

使用Google Script将Google Doc转换为Docx
EN

Stack Overflow用户
提问于 2013-03-26 19:58:26
回答 2查看 5.1K关注 0票数 9

可以使用Google脚本以编程方式将Google文档转换为Word docx文件吗?

EN

回答 2

Stack Overflow用户

发布于 2016-12-22 03:31:39

这应该是可行的

代码语言:javascript
复制
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);

}
票数 8
EN

Stack Overflow用户

发布于 2015-03-20 02:16:29

引用this item在问题跟踪器上的话...

您现在可以使用驱动器高级服务将谷歌文档转换为docx:

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

下面是一个小示例:

代码语言:javascript
复制
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();
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15636543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档