I want to list all worksheets of the workbook in a task pane. This is an office-js add-in. Ultimately I'm trying to create a table of contents, which lists the worksheets (might add range names later), and allows users to click on the sheet and be taken there. I'm great with VBA but don't know how to go about this with an Office Add-In. After several days of web searching I'm hoping to find help here. I realize this is a fairly broad question but any assistance would be greatly appreciated.
Currently I'm using yeoman generator to create my project, which is using React framework with Typescript (I'm new with both but am a quick study), and editing with VSCode.
Basically, I think what you want to do is get a reference to the Workbook.worksheets property. Load the name
property and call context.sync
. After the sync, iterate through the worksheets.items
property and add the name property of each as a <li>
element in a parent <ul>
parent in the task pane page. Something like the following, but replace the console.log with code that adds the <ul>
and <li>
s.
Excel.run(function (context) {
var worksheets = context.workbook.worksheets;
worksheets.load('name');
return context.sync()
.then(function() {
for (var i = 0; i < worksheets.items.length; i++)
{
console.log(worksheets.items[i].name);
}
});
})