Skip to content

Instantly share code, notes, and snippets.

@lumine2008
Created March 11, 2021 02:15
Show Gist options
  • Save lumine2008/9dc7994b22726ea68f23bc1a61711732 to your computer and use it in GitHub Desktop.
Save lumine2008/9dc7994b22726ea68f23bc1a61711732 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
name: workbook onActivated event
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
const book = context.workbook;
book.onActivated.add(async function added(event) {
await Excel.run(async (context) => {
console.log("workbook activated");
});
});
await context.sync();
console.log("Event Registered");
});
}
/** 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);
}
}
language: typescript
template:
content: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
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://unpkg.com/@microsoft/[email protected]/dist/office.debug.js
https://unpkg.com/@microsoft/[email protected]/dist/office-with-first-party.d.ts
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
[email protected]
@types/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment