OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
653 stars 93 forks source link

Incorrect Font Color Returned by MS Office API #4620

Open punyakrishna opened 2 days ago

punyakrishna commented 2 days ago

Description: When using the MS Office API to retrieve font color, the API returns the color as black (#000000) even though the actual color is white (#FFFFFF). This issue occurs consistently and affects the accuracy of the retrieved document styling.

Environment:

Expected behavior: The API should return the correct font color value, which in this case is white (#FFFFFF).

Current behavior: The API incorrectly returns the font color as black (#000000).

Steps to reproduce:

  1. Open the attached document in MS Office.
  2. Note the font color of the text segment in the document is set to white (#FFFFFF).
  3. Use the provided code to get the font color of the text.
  4. Observe that the API returns black (#000000) instead of white (#FFFFFF).

Document and Code: Screenshot: image

Attached Document: font-issue-doc-author-removed.docx

Code Snippet:


 $("#run").on("click", () => run());
async function loadFirstTableFontColors() {
  await Word.run(async (context) => {
    const documentTables: Word.TableCollection = context.document.body.tables.load();
    await context.sync();

    // Load font data from the first table
    const firstTable = documentTables.items[0];

    const firstTableRows: Word.TableRowCollection = firstTable.rows.load();
    await context.sync();

    let fontData = new Array(firstTableRows.items.length);

    for (let rowIndex = 0; rowIndex < firstTableRows.items.length; rowIndex++) {

      const firstTableRowCells: Word.TableCellCollection = firstTableRows.items[rowIndex].cells.load();
      await context.sync();

      fontData[rowIndex] = new Array(firstTableRowCells.items.length);

      for (let cellIndex = 0; cellIndex < firstTableRowCells.items.length; cellIndex++) {
        const cell = firstTableRowCells.items[cellIndex];

        cell.body.font.load();
        await context.sync();
        const cellFont = cell.body.font;

        await context.sync();

        fontData[rowIndex][cellIndex] = cellFont.color;
      }
    }
    console.log("First Table Font Colors:", fontData);
  });
}

function run() {
  loadFirstTableFontColors().catch((error) => {
    console.error("Error loading font colors:", error);
    if (error instanceof OfficeExtension.Error) {
      console.error('Debug info:', JSON.stringify(error.debugInfo));
    }
  });
}```
microsoft-github-policy-service[bot] commented 2 days ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

isabela-dominguez commented 2 days ago

Thank you for sharing this issue @punyakrishna! Connecting you with @shanshanzheng-dev who may be able to help.

shanshanzheng-dev commented 2 hours ago

Hi @isabela-dominguez, Thanks for reporting this issue. We'll be looking into this problem and we'll report back if we have a suggestion for you. Thanks.