Skip to content

Instantly share code, notes, and snippets.

@algomaster99
Last active July 17, 2020 10:18
Show Gist options
  • Save algomaster99/c942a984b24daaf542f9b411f559ad30 to your computer and use it in GitHub Desktop.
Save algomaster99/c942a984b24daaf542f9b411f559ad30 to your computer and use it in GitHub Desktop.
Insertion of LineBreak is automatic for the first Heading
name: ParaBodyBreak
description: Insertion of LineBreak is automatic for the first Heading
host: WORD
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function insertHeading() {
await Word.run(async context => {
const body = context.document.body;
const heading = context.document.body.insertParagraph('Heading', Word.InsertLocation.end);
heading.styleBuiltIn = Word.Style.heading1;
await context.sync();
})
}
async function insertParagraph() {
const value = "He heard the crack echo in the late afternoon about a mile away. "+
"His heart started racing and he bolted into a full sprint. \"It wasn't a gunshot, "+
"it wasn't a gunshot,\" he repeated under his breathlessness as he continued to sprint";
await Word.run(async context => {
const body = context.document.body;
const range = context.document.body.insertText(value, Word.InsertLocation.end);
range.styleBuiltIn = Word.Style.normal;
await context.sync();
})
}
async function run() {
await Word.run(async (context) => {
for (let i=0;i<3; ++i) {
insertHeading();
insertParagraph();
}
await context.sync();
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</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
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
[email protected]
@types/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment