When i copy a spreadsheet script/triggers don'

2019-02-15 23:38发布

I've created a spreadsheet with a onEdit() trigger based in a function called fillvalues() and it works fine.

I need to make several copies of this spreadsheet because it is used to make work reports, but when I make a copy the script doesn't work because the triggers are inactive or it needs authorization to run.

How can I overcome this to copy the trigger function with the new spreadsheet and to ask permission when the spreadsheet open?

1条回答
等我变得足够好
2楼-- · 2019-02-16 00:34

Each user will have to authorize and create the triggers for their copy. You can write a script that will do that for them in a function that they would run from a menu item or from a button/drawing/image in the sheet.

The code is really straightforward and goes like this (replace 'myFunction' with your function name) :

function createOnEditTrigger(){
  var trigger = ScriptApp.newTrigger("myFunction").forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()).onEdit().create();
}
查看更多
登录 后发表回答