Skip to content

Instantly share code, notes, and snippets.

@andyweiss1982
Created October 30, 2020 19:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyweiss1982/9d272c0fcda475d0ccf850305c9228aa to your computer and use it in GitHub Desktop.
Save andyweiss1982/9d272c0fcda475d0ccf850305c9228aa to your computer and use it in GitHub Desktop.
Very basic implementation of fetching data and putting into Excel
name: Dad Joke API Example
description: Very basic implementation of fetching data and putting into Excel
host: EXCEL
api_set: {}
script:
content: |
const button = document.querySelector("button");
button.addEventListener("click", run);
async function getRandomDadJoke(){
const response = await fetch("https://icanhazdadjoke.com/", {
headers: {
Accept: "application/json"
}
})
const data = await response.json()
return data.joke
}
async function run() {
const joke = await getRandomDadJoke()
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const range = sheet.getRange("A1");
range.values = [[joke]];
range.format.autofitColumns();
await context.sync();
});
}
language: typescript
template:
content: |-
<h1>Want to hear a funny joke?</h1>
<button id="run">Get Joke</button>
language: html
style:
content: |-
h1 {
color: blue;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
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
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment