Reputation: 206
So I'm trying to use the RangeAreas class inside of Scriptlab to retrieve some information from multiple ranges at once, but I can't get it to work. Here's my code:
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
var sheet = context.workbook.worksheets.getActiveWorksheet();
var rangeAreas = sheet.getRanges("F3:F5, H3:H5");
rangeAreas.load("address");
await context.sync();
console.log(rangeAreas.address);
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
And this is the error I get in Scriptlab's console:
c {name: "RichApi.Error", code: "InvalidArgument", traceMessages: Array[0], innerError: null, debugInfo: Object…}
name: "RichApi.Error"
code: "InvalidArgument"
traceMessages: Array[0]
innerError: null
▶debugInfo: Object
code: "InvalidArgument"
message: "L’argument est manquant ou non valide, ou a un format incorrect."
toString: function ()
errorLocation: "Worksheet.getRanges"
statement: "var ranges=activeWorksheet.getRanges(...);"
▶surroundingStatements: Array[8]
0: "var workbook=context.workbook;"
1: "var worksheets=workbook.worksheets;"
2: "var activeWorksheet=worksheets.getActiveWorksheet();"
3: "// >>>>>"
4: "var ranges=activeWorksheet.getRanges(...);"
5: "// <<<<<"
6: "// Instantiate {ranges}"
7: "ranges.load(["address"]);"
▶fullStatements: Array[6]
line: 24
column: 243520
sourceURL: "https://appsforoffice.microsoft.com/lib/1/hosted/excel-mac-16.00.js"
I'm sure I've made a silly mistake somewhere, but I just can't find where, and it's driving me mad. Any help is greatly appreciated.
Upvotes: 1
Views: 694
Reputation: 2236
Your code runs perfectly on my side. Is your system locale is in French? there is a known issue for the separator for the ranges, the separator changes based on system local.
So I guess in French it maybe uses ";", can you try the following code below?
var rangeAreas = sheet.getRanges("F3:F5; H3:H5");
Upvotes: 1