简体   繁体   中英

How do I get the true range when editing multiple rows on Google Sheet via Google App Script

I'm using a piece of Google Script to copy from one Google Sheet to another Google Sheet, but also doing some column and data manipulation (so it's not just a straight copy).

The code was inspired by this question: Event trigger to move row to one of two other sheets based on values in 2 columns

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.range;
...
}

Unfortunately it seems that when you check Multiple checkboxes in one go by highlighting multiple cells and pressing the space bar, the OnEdit event object will only detect the first cell as being edited, and the other cells not being edited.

I tested this by doing:

Browser.msgBox(event.range.getNumRows())

No matter how many Checkboxes I edit in one go; it always returns 1

Is there a correct way to get the true range of Cells edited in one go?

Thanks.

This appears to be a bug!

I gave Google's Issue Tracker a look and it appears that this also happens when deleting multiple cells with checkboxes - only the range of the first cell is passed to e.range . Here's the report which details the same kind of behaviour:

It appears that this is an issue related to the way checkbox ranges are passed to the event object as well.

Google does seem to know about this issue but if it's causing problems you can file your own bug about it here as Diego mentioned above.

You can also hit the ☆ next to the issue number in the top left on the aforementioned pages which lets Google know more people are encountering this and so it is more likely to be seen to faster.

I hope this is helpful to you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM