Skip to content

Commit

Permalink
Server/Office scripts: handle named ranges with sheet scope
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Apr 29, 2023
1 parent 5aa76e8 commit 8be1ade
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion xlwings/js/xlwings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ async function runPython(
let names: Names[] = [];
workbook.getNames().forEach((namedItem, ix) => {
// Currently filtering to named ranges
// TODO: add sheet scoped named ranges via sheets as in officejs
let itemType: ExcelScript.NamedItemType = namedItem.getType();
if (itemType === ExcelScript.NamedItemType.range) {
names[ix] = {
Expand Down Expand Up @@ -160,6 +159,26 @@ async function runPython(
lastCellCol = 0;
lastCellRow = 0;
}

// Names (sheet scope)
let namesSheetScope: Names[] = [];
sheet.getNames().forEach((namedItem, ix) => {
// Currently filtering to named ranges
let itemType: ExcelScript.NamedItemType = namedItem.getType();
if (itemType === ExcelScript.NamedItemType.range) {
namesSheetScope[ix] = {
name: namedItem.getName(),
sheet_index: namedItem.getRange().getWorksheet().getPosition(),
address: namedItem.getRange().getAddress().split("!").pop(),
book_scope: false,
};
}
});

// Add sheet scoped names to book scoped names
payload["names"] = payload["names"].concat(namesSheetScope);

// values
if (isSheetIncluded) {
let range = sheet.getRangeByIndexes(
0,
Expand Down

0 comments on commit 8be1ade

Please sign in to comment.