Skip to content

Instantly share code, notes, and snippets.

@rheajt
Created April 20, 2020 05:32
Show Gist options
  • Save rheajt/801e17b9adfff8b0a6a9b805e37b5999 to your computer and use it in GitHub Desktop.
Save rheajt/801e17b9adfff8b0a6a9b805e37b5999 to your computer and use it in GitHub Desktop.
[UpdateNamedRangs] excel typescript to update the ranges of all named ranges in a workbook #excel #typescript
async function main(context: Excel.RequestContext) {
// Your code here
const items = context.workbook.names.load('items')
await context.sync();
items.items.forEach(item => {
const lastIndex = item.formula.lastIndexOf('$');
const main = item.formula.substring(0, lastIndex + 1);
const split = +item.formula.substring(lastIndex + 1);
console.log(main, split +5);
item.set({formula: `${main}${split + 5}`});
});
await context.sync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment