脚本停止,可能是由于先调用了onEdit()SpreadsheetApp然后调用了DocumentApp [英] Script stopping, may be due to onEdit() SpreadsheetApp call and then DocumentApp call

查看:73
本文介绍了脚本停止,可能是由于先调用了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..

他们可以修改绑定到的文件,但不能访问其他文件 文件,因为这需要授权.

They can modify the file they are bound to, but cannot access other files because that would require authorization.

请参阅以了解授权方式和您可以在每个选项下做什么.可能是下面的第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..

例如,激活Google表格的可安装打开触发器 只要具有编辑权限的任何用户打开电子表格, 就像简单的onOpen()触发器一样.但是,可安装 版本可以调用需要授权的服务.可安装 该版本在创建该用户的用户的授权下运行 触发,即使其他具有编辑权限的用户打开电子表格

For example, the installable open trigger for Google Sheets activates whenever the spreadsheet is opened by any user who has edit access, just like the simple onOpen() trigger. However, the installable version can call services that require authorization. The installable version runs with the authorization of the user who created the trigger, even if another user with edit access opens the spreadsheet

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

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