From a60a1a173dc9e6196c7647750232105665a337da Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 15:58:53 +0100 Subject: [PATCH 01/10] remove isNullObject --- src/word-plugin/src/taskpane/taskpane.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index b576065..dfb5219 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -94,7 +94,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; @@ -176,7 +176,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; From 3dca24ce382b2c959da5d6f10aa12fc0993b22b7 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:08:24 +0100 Subject: [PATCH 02/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index dfb5219..766df62 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -26,7 +26,7 @@ export async function run1() { // load text //paragraphs.load("$all"); - paragraphs.load(["text"]); + paragraphs.load(["text", "items"]); await context.sync(); document.getElementById("progressbar").style.width = "10%"; @@ -135,7 +135,7 @@ export async function run2() { // load text //paragraphs.load("$all"); - paragraphs.load("text"); + paragraphs.load(["text", "items"]); await context.sync(); document.getElementById("progressbar").style.width = "10%"; From 0485144f9c2e94f2ddeb29a63ebec3a7b791691c Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:09:50 +0100 Subject: [PATCH 03/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index 766df62..b0985aa 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -5,8 +5,11 @@ /* global document, Office, Word */ +const addinVersion = "1.0"; + 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("run1").onclick = run1; From 78f8906d2900fad8e843e3133b61d33cb409300b Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:10:58 +0100 Subject: [PATCH 04/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index b0985aa..e68b80f 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -18,7 +18,7 @@ Office.onReady((info) => { }); export async function run1() { - console.log("Run V1"); + console.log(`Run V1 - (V${addinVersion})`); return await Word.run(async (context) => { let start = performance.now(); @@ -127,7 +127,7 @@ export async function run1() { } export async function run2() { - console.log("Run V2"); + console.log(`Run V2 - (V${addinVersion})`); return await Word.run(async (context) => { const start = performance.now(); From f1f4c74e23eb4c536082e7c39b2e6e8f42047b92 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:21:36 +0100 Subject: [PATCH 05/10] update --- src/word-plugin/src/taskpane/taskpane.html | 8 ++++++-- src/word-plugin/src/taskpane/taskpane.ts | 23 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.html b/src/word-plugin/src/taskpane/taskpane.html index eda1267..50f8089 100644 --- a/src/word-plugin/src/taskpane/taskpane.html +++ b/src/word-plugin/src/taskpane/taskpane.html @@ -34,12 +34,16 @@

Please + + Demo + + - Run V1 + Run V1 - Run V2 + Run V2 diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index e68b80f..6b74885 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -12,11 +12,27 @@ Office.onReady((info) => { 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) => { + const doc = context.document; + const originalRange = doc.getSelection(); + originalRange.insertText(" (M365)", Word.InsertLocation.end); + + originalRange.load("text"); + await context.sync(); + + doc.body.insertParagraph("Original range: " + originalRange.text, Word.InsertLocation.end); + + await context.sync(); + }); +} + export async function run1() { console.log(`Run V1 - (V${addinVersion})`); return await Word.run(async (context) => { @@ -137,9 +153,10 @@ export async function run2() { const paragraphs = context.document.body.paragraphs; // load text - //paragraphs.load("$all"); - paragraphs.load(["text", "items"]); - await context.sync(); + paragraphs.load("$all"); + //paragraphs.load(["text", "items"]); + //await context.sync(); + await paragraphs.context.sync(); document.getElementById("progressbar").style.width = "10%"; From c037a312dc4507dd88f4b0b6aadd66aa9516474c Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:21:47 +0100 Subject: [PATCH 06/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index 6b74885..62680f5 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -5,7 +5,7 @@ /* global document, Office, Word */ -const addinVersion = "1.0"; +const addinVersion = "1.1"; Office.onReady((info) => { if (info.host === Office.HostType.Word) { From 0fbb4d6facd4faec446d462053b4d7a2df3c26ba Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:25:17 +0100 Subject: [PATCH 07/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index 62680f5..da84f60 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -5,7 +5,7 @@ /* global document, Office, Word */ -const addinVersion = "1.1"; +const addinVersion = "1.2"; Office.onReady((info) => { if (info.host === Office.HostType.Word) { @@ -44,9 +44,9 @@ export async function run1() { const paragraphs = context.document.body.paragraphs; // load text - //paragraphs.load("$all"); - paragraphs.load(["text", "items"]); - await context.sync(); + paragraphs.load("$all"); + //paragraphs.load(["text", "items"]); + await paragraphs.context.sync(); document.getElementById("progressbar").style.width = "10%"; From fe0a81e84bc73cc8a13c8769e84f7da0c005c0e2 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Thu, 7 Mar 2024 16:30:31 +0100 Subject: [PATCH 08/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index da84f60..690d434 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -5,7 +5,7 @@ /* global document, Office, Word */ -const addinVersion = "1.2"; +const addinVersion = "1.3"; Office.onReady((info) => { if (info.host === Office.HostType.Word) { @@ -59,6 +59,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([" "]); From eedf8e97971b9565c4f06840c2ce0fd1fc8bd448 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Fri, 8 Mar 2024 14:12:41 +0100 Subject: [PATCH 09/10] update --- src/word-plugin/src/taskpane/taskpane.ts | 58 ++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index 690d434..1f2e00e 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -3,6 +3,8 @@ * See LICENSE in the project root for license information. */ +import { container } from "webpack"; + /* global document, Office, Word */ const addinVersion = "1.3"; @@ -20,14 +22,60 @@ Office.onReady((info) => { export async function insertTextIntoRange() { await Word.run(async (context) => { - const doc = context.document; - const originalRange = doc.getSelection(); - originalRange.insertText(" (M365)", Word.InsertLocation.end); - originalRange.load("text"); + var paragraph = context.document.body.paragraphs.getFirst(); + context.load(paragraph, ["text", "font"]); + + await context.sync(); + + var words = paragraph.getTextRanges([" "], true); + context.load(words, ["text", "font"]); + + var boldRanges = []; await context.sync(); - doc.body.insertParagraph("Original range: " + originalRange.text, Word.InsertLocation.end); + for (var i = 0; i < words.items.length; ++i) { + var word = words.items[i]; + if (word.font.bold) { + boldRanges.push(word); + } + } + + for (var j = 0; j < boldRanges.length; ++j) { + boldRanges[j].font.highlightColor = "#FF00FF"; + } + + console.log("done"); + + // const paragraphs = context.document.body.paragraphs; + + // const paragraph = paragraphs.getFirst(); + // paragraph.style.font.bold = true; + + // paragraph.load("text"); + // await context.sync(); + + // console.log(paragraph.text); + + // const range = paragraph.getRange(); + // range.load("test"); + // await context.sync(); + // console.log(range.text); + + // const words = range.split([""]); + // console.log(words.items.length); + + // console.log("load items"); + // range.load("items"); + // await context.sync(); + + // console.log(words); + // console.log(words.items.length); + + // words.load("items"); + // await words.context.sync(); + // console.log(words); + // words[0].style.font.bold = true; await context.sync(); }); From e3e8d250174935356d707ef428275da01abd37ec Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Mon, 11 Mar 2024 13:02:07 +0100 Subject: [PATCH 10/10] Update taskpane.ts --- src/word-plugin/src/taskpane/taskpane.ts | 99 ++++++++++++++---------- 1 file changed, 57 insertions(+), 42 deletions(-) diff --git a/src/word-plugin/src/taskpane/taskpane.ts b/src/word-plugin/src/taskpane/taskpane.ts index 1f2e00e..3be331f 100644 --- a/src/word-plugin/src/taskpane/taskpane.ts +++ b/src/word-plugin/src/taskpane/taskpane.ts @@ -22,62 +22,77 @@ Office.onReady((info) => { export async function insertTextIntoRange() { await Word.run(async (context) => { + let start = performance.now(); - var paragraph = context.document.body.paragraphs.getFirst(); - context.load(paragraph, ["text", "font"]); + var paragraphs = context.document.body.paragraphs; + context.load(paragraphs, ["items"]); await context.sync(); - var words = paragraph.getTextRanges([" "], true); - context.load(words, ["text", "font"]); + console.log(paragraphs.items.length); - var boldRanges = []; - await context.sync(); + const words1: Word.RangeCollection[] = []; - for (var i = 0; i < words.items.length; ++i) { - var word = words.items[i]; - if (word.font.bold) { - boldRanges.push(word); - } - } + for (let x = 0; x < paragraphs.items.length; ++x) { + const paragraph = paragraphs.items[x]; + console.log(`load paragraph ${x}`); - for (var j = 0; j < boldRanges.length; ++j) { - boldRanges[j].font.highlightColor = "#FF00FF"; + var words = paragraph.getTextRanges([" "], true); + words1.push(words); } - console.log("done"); - - // const paragraphs = context.document.body.paragraphs; - - // const paragraph = paragraphs.getFirst(); - // paragraph.style.font.bold = true; - - // paragraph.load("text"); - // await context.sync(); - - // console.log(paragraph.text); - - // const range = paragraph.getRange(); - // range.load("test"); - // await context.sync(); - // console.log(range.text); - - // const words = range.split([""]); - // console.log(words.items.length); + for (const words of words1) { + context.load(words, ["items"]); + } + await context.sync(); - // console.log("load items"); - // range.load("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; + // } + // } + } + } - // console.log(words); - // console.log(words.items.length); + await context.sync(); - // words.load("items"); - // await words.context.sync(); - // console.log(words); - // words[0].style.font.bold = true; + 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`); }); }