【问题标题】:How to convert .docx files to Google Docs with Apps Script?使用 App 脚本将 .docx 转换为 Google Docs
【发布时间】:2019-12-30 18:13:42
【问题描述】:

有人有将存储在 Google Drive 中的一批 .docx 文件转换为 Google Doc 格式的经验吗?

我阅读了 Youssef 3 年前发布的解决方案,但它不再起作用了。

Docx to Google Doc using Google Script

当我尝试在下面复制他的解决方案时,我收到以下错误消息:很抱歉,发生了服务器错误。请稍等,然后重试。

var docx = DriveApp.getFileById("###");

var newDoc = Drive.newFile();
var blob =docx.getBlob();
var file=Drive.Files.insert(newDoc,blob,{convert:true});

代码停在docx.getBlob()

非常感谢您的支持!

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    此功能使用一些高级 Drive API,因此,需要您先从脚本编辑器启用它们,运行脚本之前。为此,请转到:

    资源 > 高级 Google 服务... > 一直向下滚动到 Drive API > 将 关闭 按钮切换到

    这是最终脚本 -

    function myFunction() {
      var docx = DriveApp.getFilesByName('Dummy.docx').next();
      var newDoc = Drive.newFile();
      var blob =docx.getBlob();
      var file=Drive.Files.insert(newDoc,blob,{convert:true});
      DocumentApp.openById(file.id).setName(docx.getName());  
    }
    

    希望这会有所帮助!

    【讨论】:

    • 嗨,Sourabh!感谢您的反馈意见!我运行您的代码,但它仍然停在调用 getBlob() 方法的行上。我还启用了 Drive API 的高级服务。它可以在你身边正常工作吗?
    • Sourabh,我查看了我的代码,它现在可以工作了。非常感谢!
    • 抱歉,错过了您之前的评论,但很高兴我能提供帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2022-01-15
    • 2021-12-15
    • 2020-12-08
    • 1970-01-01
    • 2021-05-21
    相关资源
    最近更新 更多