Skip to content

Instantly share code, notes, and snippets.

@akrantz
Last active January 26, 2018 01:55
Show Gist options
  • Save akrantz/e2afdbe0215c2c1fa25c4baaaa127cd9 to your computer and use it in GitHub Desktop.
Save akrantz/e2afdbe0215c2c1fa25c4baaaa127cd9 to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: Daedalus
description: ''
author: akrantz
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(main));
const BatchFunction = function (workbook: Excel.Workbook): Promise<any> { return Promise.resolve() };
async function main() {
return Excel.run(async (batch) => {
const stockCells = await batch((workbook) => {
const worksheet = workbook.worksheets.getActiveWorksheet();
const columnRange = worksheet.getRange().getColumn(0).getUsedRange(true);
return columnRange.retrieve('values', 'address');
});
console.log(stockCells);
console.log(stockCells.toJSON());
const stocks = stockCells.values.join();
const response = await $.ajax(`https://api.iextrading.com/1.0/stock/market/batch?symbols=${stocks}&types=quote`);
console.log(response);
});
}
function updateCellValue(batch, cell: Excel.Range, value: number | string | boolean) {
return batch(() => cell.update({ values: [[value]] }));
}
/** 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: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
//https://appsforoffice.microsoft.com/lib/1/hosted/office.js
//https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts
https://unpkg.com/@microsoft/office-js@experiment-daedalus/dist/office.js
https://unpkg.com/@microsoft/office-js@experiment-daedalus/dist/office.d.ts
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
@microsoft/[email protected]/dist/office.helpers.min.js
@microsoft/[email protected]/dist/office.helpers.d.ts
[email protected]
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment