Skip to content

Instantly share code, notes, and snippets.

@XiangGaoMSFT
Created September 3, 2018 07:31
Show Gist options
  • Save XiangGaoMSFT/4cafb6f0c1a4a981f6d0a4c2386c3b38 to your computer and use it in GitHub Desktop.
Save XiangGaoMSFT/4cafb6f0c1a4a981f6d0a4c2386c3b38 to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: Workbook.properties.custom
description: ''
author: XiangGaoMSFT
host: EXCEL
api_set: {}
script:
content: |
$("#add").click(() => tryCatch(add));
$("#load").click(() => tryCatch(load));
function add() {
return Excel.run(async (context) => {
var customDocProps = context.workbook.properties.custom;
customDocProps.add("abc", "ttttttt");
return context.sync()
.then(function () {
console.log("added");
});
});
}
function load() {
return Excel.run(async (context) => {
var customDocProps = context.workbook.properties.custom;
console.log("Proceeding to load custom properties");
context.load(customDocProps);
return context.sync()
.then(function () {
console.log("Proceeding to evaluate execute context results");
var docidprop = customDocProps.getItemOrNullObject("abc");
context.load(docidprop);
return context.sync()
.then(function () {
if (typeof (docidprop.value) === 'undefined') {
console.log("No such custom property");
} else {
console.log(docidprop.value);
}
});
});
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |
<button id="add" class="ms-Button">
<span class="ms-Button-label">Add</span>
</button>
<button id="load" class="ms-Button">
<span class="ms-Button-label">Load</span>
</button>
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
@microsoft/[email protected]/dist/office.helpers.min.js
@microsoft/[email protected]/dist/office.helpers.d.ts
[email protected]
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment