Google Apps脚本错误:“您无权调用openById”

时间:2015-06-29 18:26:15

标签: google-apps-script

我正在尝试使用我在GitHub上找到的Google脚本。 (它在下面发布。)它应该将Google表格中的数据合并到Google Doc中。但是,当我尝试运行脚本时,我收到一个错误:“您没有权限调用openById”。我研究了这个问题,而且信息是冲突的。但是,我尝试了以下内容:

  1. Manually run the function in script editor before adding the trigger to Google sheet.
  2. 授权脚本访问我的Google文档数据。
  3. Set the triggers for the function to "On Form Submit"
  4. 将脚本添加到我的Google表格并按照说明从菜单中运行:合并 - >填写模板
  5. 我继续得到错误。我看到还有其他人有同样的问题,但到目前为止提供的答案还没有解决问题。任何帮助将不胜感激。

    function doMerge() {
      var selectedTemplateId = "1foobarfoobarfoobarfoobarfoobarfoobar";//Copy and paste the ID of the template document here (you can find this in the document's URL)
    
      var templateFile = DriveApp.getFileById(selectedTemplateId);
      var mergedFile = templateFile.makeCopy();//make a copy of the template file to use for the merged File.
      mergedFile.setName("filled_"+templateFile.getName());//give a custom name to the new file (otherwise it is called "copy of ...")
      var mergedDoc = DocumentApp.openById(mergedFile.getId());
      var bodyElement = mergedDoc.getBody();//the body of the merged document, which is at this point the same as the template doc.
      var bodyCopy = bodyElement.copy();//make a copy of the body
    
      bodyElement.clear();//clear the body of the mergedDoc so that we can write the new data in it.
    

0 个答案:

没有答案