Created
April 22, 2019 22:38
-
-
Save danielgwilson/894d5125ead2a4575012326545fd4626 to your computer and use it in GitHub Desktop.
Executes a basic call using the Operational API
This file contains 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() { | |
// Custom code | |
// Store data from instructions file | |
const rangeData = [ | |
["Month", "Phones", "Tablets", "Tablets"], | |
["Jan", 8, 150, 90], | |
["Feb", 54, 77, 54], | |
["Mar", 93, 32, 100], | |
["Apr", 84, 14, 10] | |
]; | |
const sheet = workbook.worksheets.getFirst(); | |
const range = sheet.getRange("A1:D5"); | |
range.update({ values: rangeData }); | |
const usedRange = sheet.getUsedRange(); | |
const { rowCount, columnCount, values } = await usedRange.retrieve("rowCount", "columnCount", "values"); | |
// update fills | |
// start at 1 since months and device type aren't numbers | |
const cols = "ABCD"; | |
for (let i = 1; i < rowCount; i++) { | |
for (let j = 1; j < columnCount; j++) { | |
if (values[i][j] >= 100) { | |
usedRange.getCell(i, j).format.fill.update({ | |
color: "Green" | |
}); | |
} else if (values[i][j] < 20) { | |
usedRange.getCell(i, j).format.fill.update({ | |
color: "Yellow" | |
}); | |
} | |
} | |
} | |
usedRange.format.borders.getItem("EdgeBottom").update({ style: "Continuous" }); | |
usedRange.format.borders.getItem("EdgeLeft").update({ style: "Continuous" }); | |
usedRange.format.borders.getItem("EdgeRight").update({ style: "Continuous" }); | |
usedRange.format.borders.getItem("EdgeTop").update({ style: "Continuous" }); | |
usedRange.getColumn(0).format.fill.update({ color: "Blue" }); | |
usedRange.getRow(0).format.fill.update({ color: "Blue" }); | |
// const { values } = await workbook.getSelectedRange().retrieve("values"); | |
// console.log(values); | |
} | |
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 | |
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@3.3.1 | |
whatwg-fetch | |
@types/whatwg-fetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment