JavaScript - Snippets
Insert a Header and Footer
$("#add-header").click(() => tryCatch(addHeader));
$("#add-footer").click(() => tryCatch(addFooter));
async function addHeader() {
await Word.run(async (context) => {
context.document.sections
.getFirst()
.getHeader("Primary")
.insertParagraph("This is a header", "End");
await context.sync();
});
}
async function addFooter() {
await Word.run(async (context) => {
context.document.sections
.getFirst()
.getFooter("Primary")
.insertParagraph("This is a footer", "End");
await context.sync();
});
}
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
console.error(error);
}
}
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev