Last active
July 16, 2019 04:54
-
-
Save JuaneloJuanelo/61ee8983fc914592b618a9a392d15f44 to your computer and use it in GitHub Desktop.
Demonstrates how to insert a header in the document. - Shared with Script Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Insert header | |
description: Demonstrates how to insert a header in the document. | |
author: JuaneloJuanelo | |
host: WORD | |
api_set: {} | |
script: | |
content: |- | |
$("#run").click(run); | |
$("#run").click(() => tryCatch(run)); | |
async function run() { | |
await Word.run(async (context) => { | |
// Headers and footers belong to sections | |
// so in order to insert a header/footer we must obtain a section first | |
// then we have access to the "body" of the header/footer. | |
context.document.sections.getFirst() | |
.getHeader("primary").insertText("This is a header", "start"); | |
await context.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: |- | |
<p class="ms-font-m">Click to insert a header in the document</p> | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Insert header</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
body { | |
margin: 0; | |
padding: 10px; | |
} | |
/* Button customization, including overwriting some Fabric defaults */ | |
.ms-Button, .ms-Button:focus { | |
background: #2b579a; | |
border: #2b579a; | |
} | |
.ms-Button > .ms-Button-label, | |
.ms-Button:focus > .ms-Button-label, | |
.ms-Button:hover > .ms-Button-label { | |
color: white; | |
} | |
.ms-Button:hover, .ms-Button:active { | |
background: #204072; | |
} | |
.ms-Button.is-disabled, .ms-Button:disabled { | |
background-color: #f4f4f4; | |
border-color: #f4f4f4; | |
} | |
.ms-Button.is-disabled .ms-Button-label, | |
.ms-Button:disabled .ms-Button-label { | |
color: #a6a6a6; | |
} | |
language: css | |
libraries: |- | |
// Office.js | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
// NPM libraries | |
jquery@3.1.1 | |
office-ui-fabric-js@1.4.0/dist/js/fabric.min.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 | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js | |
core-js@2.4.1/client/core.min.js | |
// IntelliSense: Use dt~library_name for DefinitelyTyped or URLs to d.ts files | |
@types/office-js | |
@types/jquery | |
@types/core-js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment