Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Zlatkovsky/7701ceddae360ad3883ca867f3831a6f to your computer and use it in GitHub Desktop.
Save Zlatkovsky/7701ceddae360ad3883ca867f3831a6f to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: '(StackOverflow:44421986) Bindings'
description: ''
author: Zlatkovsky
host: EXCEL
api_set: {}
script:
content: |
$("#create-binding").click(createBinding);
$("#get-range").click(getRange);
async function createBinding() {
try {
await Excel.run(async (context) => {
let range = context.workbook.getSelectedRange();
context.workbook.bindings.add(range, Excel.BindingType.range, "TestBinding");
await context.sync();
OfficeHelpers.UI.notify("Binding added. Now move the selection elsewhere");
});
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
async function getRange() {
try {
await Excel.run(async (context) => {
let binding = context.workbook.bindings.getItem("TestBinding");
let range = binding.getRange();
range.load("address");
range.select();
await context.sync();
OfficeHelpers.UI.notify("Binding range address is " + range.address);
});
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |
<button id="create-binding" class="ms-Button">
<span class="ms-Button-label">Create binding</span>
</button>
<button id="get-range" class="ms-Button">
<span class="ms-Button-label">Get range</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.7.4/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@0.7.4/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