Google Sheets getActiveRange on change

2019-08-27 22:31发布

I have a function starting off as such

function onEdit2(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  // Returns the active cell
  var activeRange = sheet.getActiveRange();

  Logger.log(activeRange.getA1Notation());

I have this function triggered 'on change' in a spreadsheet (it was originally on edit, hence the name, but that isn't triggered by changing background color, which is kinda critical to what I'm doing with this).

This always writes A1 to the logger, no matter what part of the spreadsheet I have selected, and it does the same thing with getActiveCell in place of getActiveRange.

Is there any way to get the selected range when a script runs?

1条回答
等我变得足够好
2楼-- · 2019-08-27 23:04

This is a serious drawback with this new trigger type. There has already been an issue raised about it:

Issue 2751: SpreadSheet onChange() trigger

Visit & star the issue to receive updates. It would be helpful to add your own observations as well, since the original issue has been entered as an enhancement request, but the fact that the trigger doesn't know the changed range is bug-flavoured.

查看更多
登录 后发表回答