Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Word Addin Javascript cannot read font.color or font.highlightColor after I set it

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!