Skip to content

Instantly share code, notes, and snippets.

@JuaneloJuanelo
Last active November 7, 2018 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuaneloJuanelo/45ddbe583b70b060054cac30d9846732 to your computer and use it in GitHub Desktop.
Save JuaneloJuanelo/45ddbe583b70b060054cac30d9846732 to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: Areas+SpecialCells
description: ''
author: JuaneloJuanelo
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
$("#run2").click(() => tryCatch(specialCells));
async function run() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const rangeAreas = sheet.getRanges("A1:A5, C3:H5");
rangeAreas.format.fill.color = "pink";
await context.sync();
});
}
async function specialCells () {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const usedRange = sheet.getUsedRange();
const formulaRanges = usedRange.getSpecialCells("Formulas");
formulaRanges.format.fill.color = "green";
await context.sync();
});
}
Excel.run(function (context) {
return context.sync();
})
/** 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">Areas</span>
</button>
<br><br>
<button id="run2" class="ms-Button">
<span class="ms-Button-label">Special Cells</span>
</button>
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/beta/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
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment