Skip to content

Instantly share code, notes, and snippets.

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 glachancecmaisonneuve/490f03466adbc08017c8fbe8afcc0a8b to your computer and use it in GitHub Desktop.
Save glachancecmaisonneuve/490f03466adbc08017c8fbe8afcc0a8b to your computer and use it in GitHub Desktop.
name: Clear Headers and Footers - 1
description: ''
host: WORD
api_set: {}
script:
content: |
document.getElementById("run").onclick = function() {
console.log("test");
run();
};
async function run() {
await Word.run(async (context) => {
console.log("start");
var mySections = context.document.sections;
//note that for builds supporting 1.1 you can super simpify this to
// context.document.sections.getFirst().getHeader("primary").clear(); await context.sync();
//but this sample assumes the Word Sku is 1.1
context.load(mySections);
console.log("loaded");
await context.sync();
console.log("await");
for (var i = 0; i < mySections.items.length; i++) {
mySections.items[i].getHeader("Primary").clear();
mySections.items[i].getFooter("Primary").clear();
mySections.items[i].getHeader("FirstPage").clear();
mySections.items[i].getFooter("FirstPage").clear();
mySections.items[i].getHeader("EvenPages").clear();
mySections.items[i].getFooter("EvenPages").clear();
console.log("cleared");
}
await context.sync();
console.log("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" onclick="alert('test');run();">
Clear Headers and Footers
</button>
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.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
name: Clear Headers and Footers - 1
description: ''
author: glachancecmaisonneuve
host: WORD
api_set: {}
script:
content: |
document.getElementById("run").onclick = function () {
console.log("test");
run();
}
async function run() {
await Word.run(async (context) => {
console.log("start");
var mySections = context.document.sections;
//note that for builds supporting 1.1 you can super simpify this to
// context.document.sections.getFirst().getHeader("primary").clear(); await context.sync();
//but this sample assumes the Word Sku is 1.1
context.load(mySections);
console.log("loaded");
await context.sync();
console.log("await");
for (var i = 0; i < mySections.items.length; i++) {
mySections.items[i].getHeader("Primary").clear();
mySections.items[i].getFooter("Primary").clear();
mySections.items[i].getHeader("FirstPage").clear();
mySections.items[i].getFooter("FirstPage").clear();
mySections.items[i].getHeader("EvenPages").clear();
mySections.items[i].getFooter("EvenPages").clear();
console.log("cleared");
}
await context.sync();
console.log("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" onclick="alert('test');run();">
B
</button>
language: html
style:
content: |
/* Your style goes here */
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment