Skip to content

Instantly share code, notes, and snippets.

@n4nagappan
Created April 21, 2018 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n4nagappan/61e74a745b6226ac2a88d88e83b55c55 to your computer and use it in GitHub Desktop.
Save n4nagappan/61e74a745b6226ac2a88d88e83b55c55 to your computer and use it in GitHub Desktop.
Executes a basic Excel API call - Shared with Script Lab
name: Basic API call
description: Executes a basic Excel API call
author: n4nagappan
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
const range = context.workbook.getSelectedRange();
range.format.fill.color = "yellow";
range.load("address");
await context.sync()
$.get("http://google.com", function (data) {
$(".result").html(data);
alert("Load was performed.");
});
console.log(`The range address was "${range.address}".`);
});
}
/** 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: |
<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
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
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
jquery@3.1.1
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment