Skip to content

Instantly share code, notes, and snippets.

@JanisHuser
Created July 30, 2018 10:28
Show Gist options
  • Save JanisHuser/60b84c6feeab561163794c3ade3e2eaa to your computer and use it in GitHub Desktop.
Save JanisHuser/60b84c6feeab561163794c3ade3e2eaa to your computer and use it in GitHub Desktop.
Executes a basic Excel API call using plain JavaScript & Promises - Geteilt mit Script Lab.
name: Basic API call (JavaScript)
description: Executes a basic Excel API call using plain JavaScript & Promises
author: JanisHuser
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
function run() {
return Excel.run(function (context) {
var text = document.getElementById("text").nodeValue;
var rangeN = context.workbook.
for (var i = 0; i < text.length; i++)
{
}
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);
});
}
function ROTR(n, x)
{
return (x >>> n) | (x << (32-n))
}
language: typescript
template:
content: |
<p class="ms-font-m">Executes a simple code snippet.</p>
<input type="text" id="content" />
<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