首页 > 解决方案 > DocumentApp 服务抛出“访问带有 id 的文档时服务文档失败”错误

问题描述

我正在为 Google Docs 创建一个脚本,该脚本从我所在的当前文档中获取每个元素并将其复制到另一个文档中(基本上是制作副本)。

duplicateDocument();

function duplicateDocument() {
  var currentDoc = DocumentApp.getActiveDocument().getBody();
  var targetDoc = DocumentApp.create('Speech Doc');
  var totalElements = currentDoc.getNumChildren();

  //Goes through each type of element to preserve formatting
  for( var index = 0; index < totalElements; ++index ) {
    var body = targetDoc.getBody();
    var element = currentDoc.getChild(index).copy();
    var type = element.getType();

    if( type == DocumentApp.ElementType.PARAGRAPH ){
      body.appendParagraph(element);
    }
    else if( type == DocumentApp.ElementType.TABLE){
      body.appendTable(element);
      }
    else if( type == DocumentApp.ElementType.LIST_ITEM){
      body.appendListItem(element);
      }
    else if( type == DocumentApp.ElementType.BOOKMARK ){
      body.appendBookmark(element);
    }
    } 
}

一旦我调用该函数,就会弹出此错误:

访问 ID 为 [目标文档 ID] 的文档时服务文档失败

这段代码在一两天前就起作用了……什么给出了?

标签: google-apps-scriptgoogle-docs

解决方案


问题是我在要复制的文档中添加了脚注。

删除脚注后,它复制了文档就好了。

编辑:我在 Google 的IssueTracker上打开了一个问题


推荐阅读