Is it possible to get multiple ranges by name with one call? I have a complex function that needs to grab many ranges by name and Spreadsheet.getRangeByName(name) is slowing down my script significantly. Sometimes these calls take ~2 seconds, and sometimes a single call can take ~45 seconds.
Restrictions:
- I need grab the range (not just value(s)) because the script formats, grabs A1Notation for later use, offets, etc.
- The addresses of these named ranges change as a result of other functions
What I have tried:
- Store the Range object in the Document Properties. This doesn't seem to work because Ranges only have functions. JSON.stringify(Range) returns nothing.
- Use Google Sheets API v4's batchGet function but it appears to be getting values only
For named ranges, the only method of specific acquisition is via the workbook's
getRangeByName
method. There are also workbook-level and sheet-level collections available:I originally misread your question as referring to acquiring multiple ranges by A1 notation. For this, the
RangeList
class offers a very minor speed improvement, but it currently only accepts an A1/R1C1-style input array, e.g.[ "A1", "B2", "C3" ]
, and requires the ranges to be on the same sheet.If you run this and then check Stackdriver, you can see the execution times, e.g.:
I used different ranges for each call to avoid the Apps Script server caching the reference between method comparisons.