将Google Docs文件批量转换为Microsoft Word [英] Batch convert Google Docs files to Microsoft Word

查看:343
本文介绍了将Google Docs文件批量转换为Microsoft Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google文档具有一项功能,可让您将文件导出为Microsoft Word文件.是否可以对目录中的所有Google文档文件执行此操作?我很高兴通过服务器上运行的JavaScript或Chrome中运行的某种代码来做到这一点.

Google Docs has a feature that allows you to export a file as a Microsoft Word file. Is there any way to do this for all of the Google Docs files in a directory? I'm happy to do it either with JavaScript running on the server, or something running in Chrome.

推荐答案

如何使用Google Apps脚本来实现它?可以通过Chrome浏览器使用Google Apps脚本. 此处.

How about using Google Apps Script for achieving it? Google Apps Script can be used using Chrome browser. How to use Google Apps Script is here.

示例脚本如下.

  1. 定义源文件夹ID和目标文件夹ID.
  2. 从源文件夹中检索具有Google文档mimeType的文件.
  3. 每个Google文档文件都以Microsoft Word文件的形式保存到目标文件夹中.

示例脚本:

function convertGoogleDocsToMicrosoftWord() {
  var srcfolderId = "### Folder ID ###"; // <--- Please input folder ID.
  var dstfolderId = srcfolderId; // <--- If you want to change the destination folder, please modify this.
  var files = DriveApp.getFolderById(srcfolderId).getFilesByType(MimeType.GOOGLE_DOCS);
  while (files.hasNext()) {
    var file = files.next();
    DriveApp.getFolderById(dstfolderId).createFile(
      UrlFetchApp.fetch(
        "https://docs.google.com/document/d/" + file.getId() + "/export?format=docx",
        {
          "headers" : {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()},
          "muteHttpExceptions" : true
        }
      ).getBlob().setName(file.getName() + ".docx")
    );
  }
}

注意:

  • 此示例非常简单.因此,请根据您的环境进行修改.
  • 如果源文件夹中有很多文件,则可能脚本运行时(每次执行6分钟)的限制已超过.
  • Note :

    • This sample is very simple. So please modify this for your environment.
    • If there are a lot of files in the source folder, there is a possibility that the limitation of script runtime (6 min / execution) exceeds.
    • 如果我误解了你的问题,对不起.那时,请告诉我.

      If I misunderstand your question, I'm sorry. At that time, please tell me.

      这篇关于将Google Docs文件批量转换为Microsoft Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆