Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Font Color Returned by MS Office API #4620

Closed
punyakrishna opened this issue Jun 28, 2024 · 4 comments
Closed

Incorrect Font Color Returned by MS Office API #4620

punyakrishna opened this issue Jun 28, 2024 · 4 comments
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@punyakrishna
Copy link

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:

  • API version: 1.1
  • Operating system: Windows

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 microsoft-github-policy-service bot added the Area: Word Issue related to Word add-ins label Jun 28, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Jun 28, 2024
@isabela-dominguez
Copy link
Collaborator

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

@shanshanzheng-dev
Copy link

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.

@jipyua
Copy link

jipyua commented Jul 1, 2024

hi @isabela-dominguez thanks for letting us know about this. If you input some text in the following table cells as below, you can see that the text color is actually shown as black. As for the first row, in the ooxml level, the color is stored as <w:color w:val="auto"/>, for rendering purpose compared with the background, it's shown as white from UI. And at this case, at API level we are all returning them as black.

image

@jipyua jipyua added Needs: author feedback Waiting for author (creator) of Issue to provide more info and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Jul 2, 2024
@punyakrishna
Copy link
Author

I found the solution with your assistance. The issue is now resolved. Thank you very much for your support!

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: author feedback Waiting for author (creator) of Issue to provide more info labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

4 participants