Created
April 22, 2019 23:15
-
-
Save danielgwilson/94eb586890742f64b1148c011d57bfeb to your computer and use it in GitHub Desktop.
Executes a basic call using the Operational API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Basic Operational Call - 1 | |
description: Executes a basic call using the Operational API | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
// Get the Operational workbook | |
// In a true NPM world, this will be: | |
// import Excel from 'excel'; | |
// const { workbook } = new Excel(); | |
const { workbook } = new ExcelOp.Excel(); | |
// Bind button handler to run function | |
$("#run").click(run); | |
async function run() { | |
// delete sample sheet if it exists | |
const sampleSheet = workbook.worksheets.getItem("sample"); | |
if (sampleSheet.exists()) { | |
sampleSheet.delete(); | |
} | |
// add new sample worksheet | |
const sheet = await workbook.worksheets.add("sample"); | |
const rangeData = [ | |
["Month", "Phones", "Tablets", "Tablets"], | |
["Jan", 8, 150, 90], | |
["Feb", 54, 77, 54], | |
["Mar", 93, 32, 100], | |
["Apr", 84, 14, 10] | |
]; | |
const range = sheet.getRange("A1:D5"); | |
range.update({ | |
values: rangeData | |
}); | |
// table stuff (3-4) | |
const table = await sheet.tables.add(range, true); | |
table.update({ name: "SampleTable" }); | |
// charting stuff (5-9) | |
const chart = await sheet.charts.add("LineMarkers", table.getRange()); | |
chart.update({ | |
name: "SampleChart" | |
}); | |
chart.setPosition("F1"); | |
const { width, height } = await chart.retrieve({ width: true, height: true }); | |
console.log(`Width: ${width}, Height: ${height}`); | |
await chart.axes.update({ | |
categoryAxis: { | |
title: { | |
text: "Month" | |
} | |
}, | |
valueAxis: { | |
title: { | |
text: "Devices sold" | |
} | |
} | |
}); | |
} | |
language: typescript | |
template: | |
content: | | |
<p class="ms-font-m">Usability Study Test:</p> | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run Task</span> | |
</button> | |
language: html | |
style: | |
content: '' | |
language: css | |
libraries: > | |
https://unpkg.com/@microsoft/office-js@operational/dist/office.experimental.js | |
https://unpkg.com/@microsoft/office-js@operational/dist/office.experimental.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/[email protected] | |
whatwg-fetch | |
@types/whatwg-fetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment