本文介绍了脚本停止,可能是由于先调用了onEdit()SpreadsheetApp然后调用了DocumentApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此脚本仅在最后一个函数的入口处停止:addToDocument().

this script stops just at the entry of the last function : addToDocument().

到此为止,一切都正常了.我认为是由于onEdit()和DocumentApp调用引起的问题?

Until this point all is working. I presume a problem due to onEdit() and DocumentApp call?

请注意,我的addToDocument()可以完美运行.

Note that separately, my addToDocument() works perfectly.

function onEdit() {
// simple timestamp -- when a single "t" is entered in a cell, replace it with a timestamp
// see https://productforums.google.com/d/topic/docs/rC6MpQDC7n4/discussion 
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = SpreadsheetApp.getActiveRange();
if (cell.getValue() == "t") {
cell.setValue(new Date()); 
}

formatDate() // Some Date formatting using        : 'SpreadsheetApp' call
mefCond()    // Some conditonnal formatting using : 'SpreadsheetApp' call
doCounts()   // Some numéricals opérations, using : 'SpreadsheetApp' call

//At this point the scripts enter in the following function,
//and stops on the first line. Nothing being executed.

addToDocument() // Time stamp on a document using : 'DocumentApp' call
}  

有什么想法吗?

感谢您的阅读,埃里克:-)

Thanks for reading,Eric :-)

推荐答案

手动运行OnEdit时,它以不同的权限集运行,但是触发器本身具有特定的限制,如此处.在该页面上看到..

When OnEdit is run manually it runs with a different set of permissions but while Triggers themselves have specific restrictions as mentioned here. From that page see..

请参阅以了解授权方式和您可以在每个选项下做什么.可能是下面的第2行正在影响您...

Please refer to this for the authorization modes and what you can do under each of them. May be line 2 below is affecting you...

我相信为您提供的解决方案是将简单的触发器转换为可安装的触发器. 此处详细说明了如何为您的触发器安装触发器电子表格. onEdit()函数没有任何变化,您只需运行一次安装代码段即可创建可安装的触发器.

The solution for you I believe is to convert your simple trigger into an installable trigger. Here are details how to install a trigger for your spreadsheet. Nothing will changes with respect to your onEdit() function, you just have to run installation code snippet once to create an installable trigger.

function createSpreadsheetEditTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('onEdit')
      .forSpreadsheet(ss)
      .onEdit()
      .create();
}

此处是权限的详细信息和其他详细信息.在这里,它清楚地提到您可以访问其他服务..

And here are the details on permissions and other details. In here it clearly mentions that you can access other services..

这篇关于脚本停止,可能是由于先调用了onEdit()SpreadsheetApp然后调用了DocumentApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:20