Home > database >  Get selected range in all sheets of a spreadsheet using Google App Script for Workspace add-on
Get selected range in all sheets of a spreadsheet using Google App Script for Workspace add-on

Time:07-04

I would like to get all the selected ranges in all the sheets of my spreadsheet through an unbound Google App script for a Workspace add-on.

For example, I have three sheets - A (active), B and C.

I have selected the following:

  1. A1:B5 in sheet A
  2. B3 in sheet B
  3. B2:B8 and D1:D4 in sheet C

I would like to get the selections for all the sheets, like this:

A A1:B5
B B3
C B2:B8
C D1:D4

Here's what I've tried:

// gets all sheets - working fine
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();

for (var i = 0; i < sheets.length; i  ) {

  let sheet = sheets[i]

  // prints sheet name - working fine
  console.log(sheet.getName()) 

  var rangeList = sheet.getActiveRangeList().getRanges();

  for (let range in rangeList) {
    console.log(sheet.getName(), range.getA1Notation())
  }
}
  

This is the output I'm getting:

A A1:B5
B A1:B5
C A1:B5

CodePudding user response:

As @RemcoE33 mentioned, it seems that selecting ranges from multiple spreadsheets is only returning the first selected range as stated in the Issuetracker. As of now there is no workaround to this behavior and is still an ongoing problem.

  • Related