Google Spreadsheet Script onChange event not firing

丶灬走出姿态 提交于 2020-12-09 03:21:01

问题


I am trying to fire an onChange event and it is not working.

I have the following simple code:

function onChange(){
  Logger.log("onChange event fired");
}

function onEdit(){
  Logger.log("onEdit event fired");
}

https://developers.google.com/apps-script/understanding_events

According the this document, the onChange event should be fired when a row is inserted. It does not get fired. The onEdit function gets fired when you manipulate a cell, but I need an event to be fired when the user inserts a row as well.

Any thoughts?


回答1:


Try to use signatures with one parameter:

function onChange(e){
  Logger.log("onChange event fired");
}

function onEdit(e){
  Logger.log("onEdit event fired");
}

And then register those functions in ScriptEditor:

enter image description here




回答2:


onChange is an install-able trigger. Use the following function to install the trigger.

    function createSpreadsheetChangeTrigger() {
    var ss = SpreadsheetApp.getActive();
    ScriptApp.newTrigger('onChange')
      .forSpreadsheet(ss)
      .onChange()
      .create();
    }  



回答3:


In the script editor I clicked the Resources menu and selected 'All your triggers' from there I was able to register my onChange function to actually be triggered on change of the spreadsheet.

Edit: People were telling me to do this with code, I couldn't get that to work. Found the gui method buried in the docs.



来源:https://stackoverflow.com/questions/22462699/google-spreadsheet-script-onchange-event-not-firing

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