Last active
January 25, 2024 09:08
-
-
Save jipyua/3e91c8f63372b6df4f4fe52772a279ad to your computer and use it in GitHub Desktop.
Formats text with pre-built styles.
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: Preview API testing | |
description: Formats text with pre-built styles. | |
host: WORD | |
api_set: {} | |
script: | |
content: > | |
$("#add-preset").click(() => tryCatch(run)); | |
//$("#add-preset2").click(() => tryCatch(addPreStyledFormattedText2)); | |
var firstcom; | |
var firstpar; | |
let html = '<div style="margin-left: 24.0pt; text-indent: -24.0pt; | |
text-autospace: none;">объеме пораженной </div> '; | |
async function run() { | |
await Word.run(async (ctx) => { | |
//for (var i = 0; i< 50; i++) | |
//var range1 = ctx.document.getSelection(); | |
//var ragne2 = range1.insertHtml(html, "Start"); | |
//ragne2.insertHtml(html, "End"); | |
ctx.document.body.getContentControls().getFirst().insertHtml(html, "Start"); | |
await ctx.sync(); | |
//range1.font.color = "red"; | |
//range2.select(); | |
/* var ccs = ctx.document.body.getContentControls(); | |
ccs.load(); | |
await ctx.sync(); | |
// time start | |
for (var i=0; i < ccs.items.length; i++) | |
{ | |
ccs.items[i].insertHtml(html, "Replace"); | |
} | |
await ctx.sync();*/ | |
// time end | |
//console.log(range1.value); | |
}); | |
} | |
/** 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: "<section class=\"ms-font-m\">\n This sample shows how to apply built-in styles.\n</section>\n\n<section class=\"samples ms-font-m\">\n <h3>Try it out</h3>\n <button id=\"add-preset\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Insert paragraph with preset style</span>\n </button>\n\n\t<button id=\"add-preset2\" class=\"ms-Button\">\n\t <span class=\"ms-Button-label\">Insert paragraph with preset style2</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/beta/hosted/office.js | |
@types/office-js-preview | |
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