I have the following code that sets the font.color
Word.run(async (context) => {
const newRange = await getTextRange(context, locationText, offset, length);
if (newRange === null) return null;
suggestedPosition = newRange;
suggestedPosition.load('font');
await context.sync();
suggestedPosition.font.color = 'White';
suggestedPosition.track();
await context.sync();
});
This works and changes the color to white. Then after I reopen the taskpane, I want my script to be able to find if there is any white colored text left over. I do this by searching through text.
Word.run(async function(context) {
const body = context.document.body.getRange().getTextRanges([' '], true);
context.load(body, ['text', 'font']);
await context.sync();
for (let i = 0; i < body.items.length; i += 1) {
const word = body.items[i];
if (word.font.color === 'White') console.log('found word!!!');
}
})
What I get back instead is all the colors of the rest of the text (usually #000000) but the color that I changed, I get back ''. What is it that I am doing wrong? I also tried instead of White to use a random color (#123543) but still the same weird issue.
It may be totally besides the point cause I don't know this API but your problem sounds like when we try to access a style that has been modified in javascript with the style property instead of using the getComputedStyle function.