Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Zlatkovsky/bd5e82a3cf6da021cc1af13dddebba1b to your computer and use it in GitHub Desktop.
Save Zlatkovsky/bd5e82a3cf6da021cc1af13dddebba1b to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: 'StackOverflow:43808105 getSelectedRange() or sheet name with quotes in it'
description: ''
author: Zlatkovsky
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(run);
async function run() {
try {
await Excel.run(async (context) => {
const sheetName = `My sheet's data`;
// Preemptively delete any previous incarnation of this worksheet, if any
context.workbook.worksheets.getItemOrNullObject(sheetName).delete();
const sheetAdded = context.workbook.worksheets.add(sheetName);
const rangeB2 = sheetAdded.getRange("B2").load("address");
await context.sync();
console.log(rangeB2.address);
const refetchedRange = sheetAdded.getRange(rangeB2.address);
refetchedRange.format.fill.color = "orange";
const differentFetchedRange = sheetAdded.getRange("'My sheet''s data'!B3");
differentFetchedRange.format.fill.color = "purple";
sheetAdded.activate();
});
}
catch (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 */\r\n"
language: css
libraries: |
# Office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
# CSS Libraries
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
# NPM libraries
core-js@2.4.1/client/core.min.js
@microsoft/office-js-helpers@0.6.5/dist/office.helpers.min.js
jquery@3.1.1
# IntelliSense: @types/library or node_modules paths or URL to d.ts files
@types/office-js
@types/core-js
@microsoft/office-js-helpers/dist/office.helpers.d.ts
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment