Skip to content

Instantly share code, notes, and snippets.

@jiju-MS
Created April 28, 2019 02:20
Show Gist options
  • Save jiju-MS/3ed739d55902e332f38c8b51dc926c34 to your computer and use it in GitHub Desktop.
Save jiju-MS/3ed739d55902e332f38c8b51dc926c34 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
name: Binding
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#add").click(() => tryCatch(run));
$("#delete").click(() => tryCatch(del));
async function run() {
await Excel.run(async (context) => {
var bindings = context.workbook.bindings;
bindings.add("A1:A2", "Range", "Binding.add");
// bindings.addFromSelection("Range", "Binding.Selection")
// var binding = context.workbook.bindings.getItemOrNullObject("Binding.add");
// binding.delete();
await context.sync();
console.log("Setting Created");
});
}
async function del() {
await Excel.run(async (context) => {
var binding = context.workbook.bindings.getItemOrNullObject("Binding.add");
binding.delete();
await context.sync();
console.log("Setting Created");
});
}
/** 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="add" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
<button id="delete" class="ms-Button">
<span class="ms-Button-label">del</span>
</button>
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/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@3.3.1
name: Hide&UnHide
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#add").click(() => tryCatch(run));
$("#delete").click(() => tryCatch(del));
async function run() {
await Excel.run(async (context) => {
var bindings = context.workbook.bindings;
bindings.add("A1:A2", "Range", "Binding.add");
// bindings.addFromSelection("Range", "Binding.Selection")
// var binding = context.workbook.bindings.getItemOrNullObject("Binding.add");
// binding.delete();
await context.sync();
console.log("Setting Created");
});
}
async function del() {
await Excel.run(async (context) => {
var binding = context.workbook.bindings.getItemOrNullObject("Binding.add");
binding.delete();
await context.sync();
console.log("Setting Created");
});
}
/** 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="add" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
<button id="delete" class="ms-Button">
<span class="ms-Button-label">del</span>
</button>
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/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@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment