我正在尝试使用我在GitHub上找到的Google脚本。 (它在下面发布。)它应该将Google表格中的数据合并到Google Doc中。但是,当我尝试运行脚本时,我收到一个错误:“您没有权限调用openById”。我研究了这个问题,而且信息是冲突的。但是,我尝试了以下内容:
我继续得到错误。我看到还有其他人有同样的问题,但到目前为止提供的答案还没有解决问题。任何帮助将不胜感激。
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.