What am I doing wrong when using onSelectionChange for [google-apps-script]

丶灬走出姿态 提交于 2020-05-23 14:15:06

问题


I found this trigger onSelectionChange(e) on developers.google.com it should set background to red if a single empty cell is selected. Im not getting that result with just copy and paste. I don't think Im missing a step any help would be appreciated.

/**
 * The event handler triggered when the selection changes in the spreadsheet.
 * @param {Event} e The onSelectionChange event.
 */
function onSelectionChange(e) {
  // Set background to red if a single empty cell is selected.
  var range = e.range;
  if(range.getNumRows() === 1 
      && range.getNumColumns() === 1 
      && range.getCell(1, 1).getValue() === "") {
    range.setBackground("red");
  }
}

回答1:


UPDATE:

It seems it is fully rolled out to all users. You should be able to get it working without any modification to the code. The e, event object is similar to the onEdit event object.


onSelectionChange is a recently rolled out feature. Consider waiting a few days for the feature to be rolled out to your specific project and spreadsheet.



来源:https://stackoverflow.com/questions/61408971/what-am-i-doing-wrong-when-using-onselectionchange-for-google-apps-script

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