Skip to content

Instantly share code, notes, and snippets.

@ci010
Created August 31, 2021 07:57
Show Gist options
  • Save ci010/527d8ec32f7f7935561e433308b90faa to your computer and use it in GitHub Desktop.
Save ci010/527d8ec32f7f7935561e433308b90faa to your computer and use it in GitHub Desktop.
For McGrillHill Online APIs
name: APIs Demo
description: For McGrillHill Online APIs
host: EXCEL
api_set: {}
script:
content: |
$("#addListeners").click(() => tryCatch(addListeners));
async function addListeners() {
const start = Date.now();
await Excel.run(async (context) => {
context.workbook.worksheets.onChanged.add(async (arg) => {
console.log(arg);
});
context.workbook.worksheets.onMoved.add(async (arg) => {
console.log(arg);
});
context.workbook.worksheets.onNameChanged.add(async (arg) => {
console.log(arg);
});
console.log("Listeners added!");
});
}
/** 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: "<div>Please setup listeners first: </div>\n<button id=\"addListeners\" class=\"ms-Button\" >\n <span class=\"ms-Button-label\">Add Listeners</span>\n</button>\n<div style=\"margin: 20px 0\">\n\tPlease try to\n\t<li> Rename worksheet and observe the printed event </li>\n\t<li> Move worksheet position and observe the printed event </li>\n\t<li> Insert/Delete cells and shift right/down in worksheet, and observe \"changeDirectionState\" in printed event </li>\n</div>\n<div>\n\tThis demo shows these new APIs:\n\t<li> Worksheet.onMoved event </li>\n\t<li> Worksheet.onRenamed event </li>\n\t<li> Worksheet.onChanged event's new \"changeDirectionState\" argument </li>\n</div>"
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.officeapps.live.com/afo/lib/beta/hosted/office.js
https://appsforoffice.officeapps.live.com/afo/lib/beta/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
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment