How to identify changed cell in onChange function

做~自己de王妃 提交于 2021-01-28 14:18:29

问题


I am trying to detect background color change of two cells. A while back I created the following Google Sheet function and added it as an installable trigger From spreadsheet On change since cell color changes are not detected by on Edit. I thought it worked but I just checked it now, and it is not detecting which cell's background color was changed, Any ideas?

function onChangeInstallable(e) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();
  var activeSheetName = activeSheet.getSheetName();

  if (activeSheetName == "Settings") {

    if(e.changeType == "OTHER"){

      // makes it this far ok but following line returns
      // #REF! instead of A1 notation of changed cell.

      var editedRange = SpreadsheetApp.getActiveRange().getA1Notation();

      if (editedRange == 'B43' || editedRange == 'B44'){

        setBackgroundColors();

      }
    }
  }
}

Also tried the following, but it returns a "Cell reference out of range" error.

var editedRange = activeSheet.getActiveCell().getA1Notation();

回答1:


edit: looks like this case is still broken, star issue 3269 to vote for a fix

try var editedRange = activeSheet.getActiveRange().getA1Notation();

the active spreadsheet is already being passed into the function with the e object too, fyi.

var ss = e.source;



来源:https://stackoverflow.com/questions/32879220/how-to-identify-changed-cell-in-onchange-function

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