如何解决“访问文档时服务文档失败".同时插入大量数据? [英] How to fix "Service Documents failed while accessing document" while inserting a lot of data?

查看:74
本文介绍了如何解决“访问文档时服务文档失败".同时插入大量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是源自如何解决添加大量表时的错误的后续问题

对于下面的代码,当有500个表时,我会收到以下消息.但是它可以正常工作200. Exception: Service Documents failed while accessing document with id

With the code below, I get the following message when, for 500 tables. BUt it works fine for 200 for example. Exception: Service Documents failed while accessing document with id

错误发生在第22行,如果在body = DocumentApp.getActiveDocument().getBody();

The error happens on line 22, inside de if body = DocumentApp.getActiveDocument().getBody();

您也可以尝试使用表格模板ID,但这是一张图片

You also have the table template id to try, but here is an image

图像表模板


function RequirementTemplate_Copy() {
  var templatedoc = DocumentApp.openById("1oJt02MfOIQPFptdWCwDpj5j-zFdO_Wrq-I48mUq9I-w");

  return templatedoc.getBody().getChild(1).copy()
}


function insertSpecification_withSection(){
 
  // Retuns a Table Template Copied from another Document
  reqTableItem = RequirementTemplate_Copy();
  
  var body = DocumentApp.getActiveDocument().getBody();
  // Creates X number of separated tables from the template
  for (var i = 1; i < 501; i++){
    table = reqTableItem.copy().replaceText("#Title#",String(i))
    body.appendTable(table);
    
    if((i % 100) === 0) {
      DocumentApp.getActiveDocument().saveAndClose();
      body = DocumentApp.getActiveDocument().getBody()
    } 
  }
}

推荐答案

该错误消息与要插入的表数无关,因为它出现在添加表之前.

It looks that the error message isn't related to the number of tables to be inserted because it occurs before adding the tables.

请稍等一下再试一次.如果问题仍然存在,请尝试使用其他帐户运行代码,如果代码在第二个帐户上运行,则很可能您的第一个帐户超出了限制...存在一些限制以防止滥用未发布,并且可能会更改而没有任何限制公告.

Just wait a bit an try again. If the problem persist try your code using a different account if the code runs on the second account it's very possible that you first account exceeded a limit... there are some limits to prevent abuse that aren't published and that might change without any announcement.

使用我对上一个问题的答案中建议的代码修正,并将迭代限制数更改为1000和2000可以正常工作

Using the fix suggested for the code from my answer to the previous question and changing the number for iteration limit to 1000 and 2000 works fine

以下屏幕截图显示了1000的结果

The following screenshot shows the result for 1000

这是用于测试的代码

 function insertSpecification_withSection(){
  startTime = new Date()
  console.log("Starting Function... "); 
  
  // Retuns a Table Template Copied from another Document
  reqTableItem = RequirementTemplate_Copy();
  
  var body = DocumentApp.getActiveDocument().getBody();
  // Creates X number of separated tables from the template
  for (var i = 0; i < 2000; i++){
    table = body.appendTable(reqTableItem.copy());

    //    if((i % 100) === 0) {
    //      DocumentApp.getActiveDocument().saveAndClose();
    //    }
    //    
    
  }
  endTime = new Date();
  timeDiff = endTime - startTime;
  console.log("Ending Function..."+ timeDiff + " ms"); 
  
}

function RequirementTemplate_Copy() {

  //---------------------------------------------------------------------------------------------------------------------------------------------------
  var ReqTableID = PropertiesService.getDocumentProperties().getProperty('ReqTableID');
  try{
    var templatedoc = DocumentApp.openById(ReqTableID);
  } catch (error) {
    DocumentApp.getUi().alert("Could not find the document. Confirm it was not deleted and that anyone have read access with the link.");
    //Logger.log("Document not accessible", ReqTableID)
  } 
  var reqTableItem = templatedoc.getChild(1).copy();
  //---------------------------------------------------------------------------------------------------------------------------------------------------
  return reqTableItem
}

function setReqTableID(){
  PropertiesService.getDocumentProperties().setProperty('ReqTableID', '1NS9nOb3qEBrqkcAQ3H83OhTJ4fxeySOQx7yM4vKSFu0')
}

这篇关于如何解决“访问文档时服务文档失败".同时插入大量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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