Created
October 25, 2019 08:02
-
-
Save dirvo/e8788e9c26645249c9649a436f76f928 to your computer and use it in GitHub Desktop.
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: Sample für Workshop | |
description: '' | |
host: WORD | |
api_set: {} | |
script: | |
content: | | |
$("#add-paragraph").click(() => tryCatch(addParagraph)); | |
$("#add-text-to-table").click(() => tryCatch(addTextToTable)); | |
$("#get-paragraph-style").click(() => tryCatch(getParagraphStyle)); | |
$("#get-paragraph-styles").click(() => tryCatch(getParagraphStyles)); | |
async function addParagraph() { | |
await Word.run(async (context) => { | |
context.document.body.clear(); | |
let paragraph = context.document.body.insertParagraph("Hallo Welt!", Word.InsertLocation.start); | |
paragraph.styleBuiltIn = Word.Style.heading1; | |
await context.sync(); | |
}); | |
} | |
async function addTextToTable() { | |
await Word.run(async (context) => { | |
let table = context.document.body.tables.getFirst(); | |
let cell = table.getCell(0, 0); | |
cell.body.insertText("Hallo Welt", "Start"); | |
let paragraph = context.document.body.insertParagraph("Hallo Welt!", Word.InsertLocation.start); | |
console.log("I am here."); | |
await context.sync(); | |
}); | |
} | |
async function getParagraphStyle() { | |
await Word.run(async (context) => { | |
let paragraph = context.document.body.paragraphs.getFirstOrNullObject(); | |
paragraph.load("style"); | |
await context.sync(); | |
console.log(paragraph.style); | |
}); | |
} | |
async function getParagraphStyles() { | |
await Word.run(async (context) => { | |
let paragraphs = context.document.body.paragraphs; | |
paragraphs.load("style"); | |
await context.sync(); | |
paragraphs.items.forEach(para => console.log(para.style)); | |
}); | |
} | |
/** 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: "\n<section class=\"samples ms-font-m\">\n\t\n\t<p>\n\t\t<button id=\"add-paragraph\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Add paragraph</span>\n </button>\n\t\t<p>\n\t\t\t<button id=\"add-text-to-table\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Add Text to Table</span>\n </button>\n\t\t\t<p>\n\t\t\t\t<button id=\"get-paragraph-style\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Get Paragraph Style</span>\n </button>\n\t<p>\n\t\t<button id=\"get-paragraph-styles\" class=\"ms-Button\">\n\t <span class=\"ms-Button-label\">Get Paragraph Styles</span>\n\t </button>\n</section>" | |
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 | |
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