问题
I'm developing new applications in google. I have a function that is running without any problem if it's bound in the spreadsheet but when it is offline it doesn't work. That's why I saved this script in google drive in order to be called from my google spreadsheet even if it's offline. I don't know how I link this function to my spreadsheet in order to run both offline.
function onEdit(event)
{
var DistSheet = event.source.getActiveSheet();
...
}
回答1:
If you want to use a simple trigger like onEdit
, it is unfortunately not possible (see the documentation: onEdit
is a Simple Trigger, which is restricted to Bound scripts).
However, you can accomplish this with Installable Triggers.
Code for stand alone script
ScriptApp.newTrigger('myFunction')
// insert the file ID for the spreadsheet you'd like to edit
.forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz')
.onEdit()
.create();
function myFunction() {
var DistSheet = event.source.getActiveSheet();
// continue script
}
Once you've added this to your script, click the right arrow ("play") icon. It will ask for the proper authorization and then should work after that.
You can see the documentation on Installable Triggers for more information.
来源:https://stackoverflow.com/questions/33998013/how-to-run-or-link-an-onedit-standalone-trigger-in-a-google-spreadsheet