如何将文档还原到以前的版本 [英] How to revert back document to a previous revision

查看:143
本文介绍了如何将文档还原到以前的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将GAS中的Google文档(或任何其他文档)还原到较早的版本.我设法访问了修订版,甚至下载了旧的修订版,但是如何将文档还原到指定的修订版?

I want to restore a Google doc (or any other doucment) in GAS to an earlier revision. I managed to access revisions, even to download an older revision, but how can I restore a document to a specified revision?

推荐答案

  • 您想还原到以前的Google文档版本.
  • 您想使用Google Apps脚本实现这一目标.
  • 如果我的理解正确,那么这个答案如何?

    If my understanding is correct, how about this answer?

    不幸的是,在当前阶段,API不能通过脚本直接更改Google Docs的修订版.因此,作为几种解决方法之一,我建议使用导出的数据覆盖Google Docs文件.此解决方法的流程如下.

    Unfortunately, in the current stage, the revision of Google Docs cannot be directly changed by APIs with a script. So as one of several workarounds, I would like to propose to overwrite the Google Docs file using the exported data. The flow of this workaround is as follows.

    1. 从Google Docs文件中检索带有修订ID的导出的端点.
      • 在这种情况下,Google Docs文件将导出为Microsoft Docs文件.
    1. Retrieve the exported endpoint from the Google Docs file with the revision ID.
      • In this case, the Google Docs file is exported as the Microsoft Docs file.

    通过此流程,Google Docs文件将还原为以前的版本.

    By this flow, the Google Docs file is reverted to the previous version.

    重要的一点是,当将Google Docs文件导出为Microsoft Docs文件时,在大多数情况下,覆盖的Google Docs文件不会从该版本的原始Google Docs更改.但是我不确定该解决方法是否在所有情况下都能正常工作.所以请注意这一点.

    As an important point, when the Google Docs file is exported as the Microsoft Docs file, at the most cases, the overwritten Google Docs files are not changed from the original Google Docs for the version. But I'm not sure that this workaround works perfectly for all cases. So please be careful this.

    此替代方法的示例脚本如下.在运行脚本之前,请在高级Google服务中启用Drive API .

    The sample script of this workaround is as follows. Before you run the script, please enable Drive API at Advanced Google services.

    function myFunction() {
      var revisionId = "1";  // Please set the revision ID you want to revert.
      var googleDocsFileId = "###";  // Please set the Google Docs file ID.
    
      var endpoints = Drive.Revisions.get(googleDocsFileId, revisionId).exportLinks;
      var keys = Object.keys(endpoints);
      for (var i = 0; i < keys.length; i++) {
        if (keys[i].indexOf("application/vnd.openxmlformats-officedocument") > -1) {
          var endpoint = endpoints[keys[i]] + "&access_token=" + ScriptApp.getOAuthToken();
          var mediaData = UrlFetchApp.fetch(endpoint).getBlob();
          Logger.log(mediaData.getBytes().length)
          Drive.Files.update({}, googleDocsFileId, mediaData);
          break;
        }
      }
    }
    

    注意:

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