Skip to content

Instantly share code, notes, and snippets.

@kbrandl
Last active January 28, 2018 16:26
Show Gist options
  • Save kbrandl/a4a1e4da51385707863aec0ebdf296f6 to your computer and use it in GitHub Desktop.
Save kbrandl/a4a1e4da51385707863aec0ebdf296f6 to your computer and use it in GitHub Desktop.
List the worksheets in the workbook - Shared with Script Lab
name: 48482800-list-worksheets
description: List the worksheets in the workbook
author: kbrandl
host: EXCEL
api_set: {}
script:
content: |
$("#list-worksheets").click(listWorksheets);
async function listWorksheets() {
try {
await Excel.run(async (context) => {
const sheets = context.workbook.worksheets;
let worksheetNames = "";
sheets.load("items/name");
await context.sync();
for (let i in sheets.items) {
worksheetNames += sheets.items[i].name + "<br/>";
}
$('#result').html(worksheetNames);
});
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |
<section class="samples ms-font-m">
<h3>Try it out</h3>
<button id="list-worksheets" class="ms-Button">
<span class="ms-Button-label">List worksheets</span>
</button>
<br/>
<h3>Results:</h3>
<span id="result">--</span>
</section>
language: html
style:
content: |
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |-
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
jquery@3.1.1
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment