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: rramona2
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(run);
function run() {
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 + "\".");
});
})
.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: |
# Office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
# CSS Libraries
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
# NPM libraries
core-js@2.4.1/client/core.min.js
@microsoft/office-js-helpers@0.7.1/dist/office.helpers.min.js
jquery@3.1.1
# IntelliSense: @types/library or node_modules paths or URL to d.ts files
@types/office-js
@types/core-js
@microsoft/office-js-helpers@0.7.1/dist/office.helpers.d.ts
@types/jquery