When i copy a spreadsheet script/triggers don'

2019-02-16 00:05发布

问题:

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:

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();
}