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

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

问题描述

Google Docs 的一项功能允许您将文件导出为 Microsoft Word 文件.有没有办法对目录中的所有 Google Docs 文件执行此操作?我很乐意使用在服务器上运行的 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 Script 来实现它?可以使用 Chrome 浏览器使用 Google Apps 脚本.如何使用 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 Docs 的 mimeType 的文件.
  3. 每个 Google Docs 文件都作为 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分钟/执行)超过.
  • 如果我误解了你的问题,我很抱歉.到时候请告诉我.

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

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

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