Skip to content

Commit

Permalink
Merge branch 'broken'
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Mar 11, 2024
2 parents 6bf3cbc + e3e8d25 commit f59195b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/word-plugin/src/taskpane/taskpane.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ <h2 class="ms-font-xl">Please <a target="_blank" href="https://learn.microsoft.c
</div>

<div style="display: block; margin-top: 30px;">
<span role="button" id="runDemo" class="ms-Button ms-Button--hero ms-font-xl">
<span class="ms-Button-label" style="background-color: rgb(187, 102, 32); color: #fff; padding: 14px;">Demo</span>
</span>

<span role="button" id="run1" class="ms-Button ms-Button--hero ms-font-xl">
<span class="ms-Button-label" style="background-color: rgb(0, 69, 160); color: #fff; padding: 20px;">Run V1</span>
<span class="ms-Button-label" style="background-color: rgb(0, 69, 160); color: #fff; padding: 14px;">Run V1</span>
</span>

<span role="button" id="run2" class="ms-Button ms-Button--hero ms-font-xl">
<span class="ms-Button-label" style="background-color: rgb(0, 153, 64); color: #fff; padding: 20px;">Run V2</span>
<span class="ms-Button-label" style="background-color: rgb(0, 153, 64); color: #fff; padding: 14px;">Run V2</span>
</span>
</div>

Expand Down
105 changes: 95 additions & 10 deletions src/word-plugin/src/taskpane/taskpane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,101 @@
* See LICENSE in the project root for license information.
*/

import { container } from "webpack";

/* global document, Office, Word */

const addinVersion = "1.3";

Office.onReady((info) => {
if (info.host === Office.HostType.Word) {
console.log(`AddIn - V${addinVersion}`);
document.getElementById("sideload-msg").style.display = "none";
document.getElementById("app-body").style.display = "flex";
document.getElementById("runDemo").onclick = insertTextIntoRange;
document.getElementById("run1").onclick = run1;
document.getElementById("run2").onclick = run2;
}
});

export async function insertTextIntoRange() {
await Word.run(async (context) => {
let start = performance.now();

var paragraphs = context.document.body.paragraphs;

context.load(paragraphs, ["items"]);
await context.sync();

console.log(paragraphs.items.length);

const words1: Word.RangeCollection[] = [];

for (let x = 0; x < paragraphs.items.length; ++x) {
const paragraph = paragraphs.items[x];
console.log(`load paragraph ${x}`);

var words = paragraph.getTextRanges([" "], true);
words1.push(words);
}

for (const words of words1) {
context.load(words, ["items"]);
}
await context.sync();

console.log("process words...");
const chars1: Word.RangeCollection[] = [];
for (const words of words1) {
for (var i = 0; i < words.items.length; ++i) {
const charRanges = words.items[i].search("?", { matchWildcards: true });
chars1.push(charRanges);
//charRanges.load();
context.load(charRanges, ["items", "font"]);
// await charRanges.context.sync();

// for (let z = 0; z < charRanges.items.length; ++z) {
// //console.log(charRanges.items[z].text);
// if (z < 2) {
// charRanges.items[z].font.bold = true;
// }
// }
}
}

await context.sync();

console.log("process chars...");
for (const charRanges of chars1) {
// const charRanges = words.items[i].search("?", { matchWildcards: true });
// chars1.push(charRanges);
// //charRanges.load();
// context.load(charRanges, ["items"]);
// await charRanges.context.sync();

for (let z = 0; z < charRanges.items.length; ++z) {
//console.log(charRanges.items[z].text);
if (z < 2) {
if (charRanges.items[z].font.bold !== true) {
charRanges.items[z].font.bold = true;
}
} else {
//charRanges.items[z].font.bold = false;
}
}
}

console.log("last sync step, update document");
await context.sync();
console.log("done");

const end = performance.now();
console.log(`Execution time context sync: ${end - start} ms`);
});
}

export async function run1() {
console.log("Run V1.1");
console.log(`Run V1 - (V${addinVersion})`);
return await Word.run(async (context) => {
let start = performance.now();

Expand All @@ -25,9 +107,9 @@ export async function run1() {
const paragraphs = context.document.body.paragraphs;

// load text
//paragraphs.load("$all");
paragraphs.load(["text"]);
await context.sync();
paragraphs.load("$all");
//paragraphs.load(["text", "items"]);
await paragraphs.context.sync();

document.getElementById("progressbar").style.width = "10%";

Expand All @@ -40,6 +122,8 @@ export async function run1() {
for (let i = 0; i < paragraphs.items.length; i++) {
const paragraph = paragraphs.items[i];

paragraph.load("text");

// only process if text available
if (paragraph.text) {
const wordsRangeCollection = paragraph.getRange().split([" "]);
Expand Down Expand Up @@ -94,7 +178,7 @@ export async function run1() {
for (let j = 0; j < wordChars.length; j++) {
const wordChar = wordChars[j];
try {
if (wordChar && !wordChar.isNullObject) {
if (wordChar) {
if (wordChar.items.length > 2) {
wordChar.items[1].font.bold = true;
wordChar.items[2].font.bold = true;
Expand Down Expand Up @@ -124,7 +208,7 @@ export async function run1() {
}

export async function run2() {
console.log("Run V2.1");
console.log(`Run V2 - (V${addinVersion})`);
return await Word.run(async (context) => {
const start = performance.now();

Expand All @@ -134,9 +218,10 @@ export async function run2() {
const paragraphs = context.document.body.paragraphs;

// load text
//paragraphs.load("$all");
paragraphs.load("text");
await context.sync();
paragraphs.load("$all");
//paragraphs.load(["text", "items"]);
//await context.sync();
await paragraphs.context.sync();

document.getElementById("progressbar").style.width = "10%";

Expand Down Expand Up @@ -176,7 +261,7 @@ export async function run2() {
for (let j = 0; j < wordChars.length; j++) {
const wordChar = wordChars[j];

if (wordChar && !wordChar.isNullObject) {
if (wordChar) {
if (wordChar.items.length > 2) {
wordChar.items[1].font.bold = true;
wordChar.items[2].font.bold = true;
Expand Down

0 comments on commit f59195b

Please sign in to comment.