How to run or link an OnEdit standalone trigger in a google spreadsheet

↘锁芯ラ 提交于 2019-12-11 10:11:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!