Skip to content

Instantly share code, notes, and snippets.

@lumine2008
Created April 26, 2018 09:34
Show Gist options
  • Save lumine2008/fe9a1fe2ff944a559dfd55174fbe3543 to your computer and use it in GitHub Desktop.
Save lumine2008/fe9a1fe2ff944a559dfd55174fbe3543 to your computer and use it in GitHub Desktop.
Executes a basic Excel API call using plain JavaScript & Promises - Shared with Script Lab
name: Basic API call (JavaScript)
description: Executes a basic Excel API call using plain JavaScript & Promises
author: lumine2008
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
function run() {
return Excel.run(function (context) {
var range = context.workbook.getSelectedRange();
range.format.fill.color = "yellow";
range.load("address");
return context.sync()
.then(function () {
console.log("The range address was \"" + range.address + "\".");
});
});
}
/** Default helper for invoking an action and handling errors. */
function tryCatch(callback) {
Promise.resolve()
.then(callback)
.catch(function (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
});
}
language: typescript
template:
content: |
<p class="ms-font-m">Executes a simple code snippet.</p>
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run code</span>
</button>
language: html
style:
content: ''
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.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
@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