Google Doc的脚本.makeCopy()是否未复制注释? [英] Script for a Google Doc .makeCopy() the comments aren't copied?

查看:126
本文介绍了Google Doc的脚本.makeCopy()是否未复制注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在复制Google文档文档时也复制复制文档"中的注释.因为我尝试使用TEMPLATE_DOC_ID进行了此操作,该注释包含很多注释,但是在副本"中找不到注释我想念什么吗?这是另一种方法吗?谢谢!

Hello is possible twhen copying a Google Doc document to copy also the comments in the "copy doc."Because I've tried this with the TEMPLATE_DOC_ID which has many comments and I don't find the comments in the "copy".I am missing something?It's another method? Thanks!

//Make a copy of the template file
        var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();

推荐答案

不幸的是,由makeCopy()复制的Google文档不包含注释.因此,在复制文件后,需要将评论和答复插入复制的文件中.为了实现这一点,请在高级Google服务和API控制台中启用Drive API.

Unfortunately, the Google Docs copied by makeCopy() don't include the comments. So the comments and replies are required to be inserted to the copied file, after the file was copied. In order to implement this, please enable Drive API at Advanced Google Services and API console.

  • 在脚本编辑器上
    • 资源->高级Google服务
    • 打开Drive API v2
    • On script editor
      • Resources -> Advanced Google Services
      • Turn on Drive API v2

      关于驱动器API,在您的环境中,可能已启用此功能.

      About Drive API, in your environment, this might have already been enabled.

      • 在脚本编辑器上
        • 资源-> Cloud Platform项目
        • View API控制台
        • 在入门"中,单击启用API"并获取凭据(例如密钥).
        • 在左侧,单击库.
        • 在搜索API和服务,输入驱动器".然后点击Drive API.
        • 单击启用"按钮.
        • 如果已启用API,请不要关闭.
        • On script editor
          • Resources -> Cloud Platform project
          • View API console
          • At Getting started, click Enable APIs and get credentials like keys.
          • At left side, click Library.
          • At Search for APIs & services, input "Drive". And click Drive API.
          • Click Enable button.
          • If API has already been enabled, please don't turn off.
          var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();
          
          // Added script
          var commentList = Drive.Comments.list(TEMPLATE_DOC_ID);
          commentList.items.forEach(function(item) {
            var replies = item.replies;
            delete item.replies;
            var commentId = Drive.Comments.insert(item, documentId).commentId;
            replies.forEach(function(reply) {
              Drive.Replies.insert(reply, documentId, commentId).replyId;
            });
          });
          

          注意:

          • 很遗憾,创建时间和修改时间无法更新.因此,该日期将成为创建日期.
            • Advanced Google Services
            • Drive API
            • Comments: insert
            • Replies: insert

            如果这不是您想要的,对不起.

            If this was not what you want, I'm sorry.

            这篇关于Google Doc的脚本.makeCopy()是否未复制注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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