Skip to content

Instantly share code, notes, and snippets.

@anmarant
Last active December 1, 2019 18:23
Show Gist options
  • Select an option

  • Save anmarant/36184c261d3046fbe81633d4e215d184 to your computer and use it in GitHub Desktop.

Select an option

Save anmarant/36184c261d3046fbe81633d4e215d184 to your computer and use it in GitHub Desktop.
Demo Excel 365 API call
name: Demo Excel 365 -v2
description: Demo Excel 365 API call
host: EXCEL
api_set: {}
script:
content: |
//$("#run").click(() => tryCatch(run));
$("#submitStockData").click(() => tryCatch(getStockData));
function getStockData() {
var stockId = $('#stockId').val();
var dataUrl = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=' + stockId + '&interval=5min&apikey=CFB1YOLQLQ996EJO'; console.log(dataUrl);
console.log(dataUrl);
}
$.ajax({
type: 'GET',
url: 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=CFB1YOLQLQ996EJO',
success: function (responseData) {
var timeSeriesData = responseData['Time Series (5min)'];
},
error: function printError(errorMessage) {
console.log(errorMessage);
}
})
async function run() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
console.log("Your code goes here");
await context.sync();
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: "<div class=\"jumbotron\">\n\t<div id=\"content-main\">\n\t\t<div class=\"padding\">\n\t\t\t<h1> Share Price Data </h1>\n\t\t\t<hr />\n\t\t\t<form>\n\t\t\t\t<div class=\"form-group\">\n\t\t\t\t\t<label for=\"exampleInputEmail1\">Stock Ticker</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"stockId\" placeholder=\"Inserisci stock ticker\">\n </div>\n\t\t\t\t\t<button id=\"submitStockData\" type=\"submit\" class=\"btn btn-primary\">submit</button>\n\t\t\t</form>\n\t\t</div>\n\t</div>\n</div>"
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
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
https://unpkg.com/bootstrap@4.1.0/dist/css/bootstrap.min.css
name: Demo Excel 365
description: Demo Excel 365 API call
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
console.log("Your code goes here");
await context.sync();
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: |-
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
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
https://unpkg.com/bootstrap@4.1.0/dist/css/bootstrap.min.css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment