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
671 stars 95 forks source link

Shading Color Returning Empty String and Missing shd Tag in XML #4632

Closed punyakrishna closed 1 month ago

punyakrishna commented 3 months ago

Description:

Environment: API version: 1.1 Operating system: Windows

Expected behavior:

Current behavior:

Steps to reproduce:

  1. Open the attached document containing a table.
  2. Use the provided code to get the shading color of the table cells.
  3. Observe that the returned shading color is an empty string.
  4. Observe that the visibility color is incorrectly returned as an empty string instead of black.
  5. Inspect the XML of the table and notice that the shd tag is missing.

Document and Code: Screenshot: image

Attached Document: shading-issue.docx

Code Snippet:

  async function loadFirstTableFontColors() {
      await Word.run(async (context) => {
        const documentTables: Word.TableCollection = context.document.body.tables.load();
        await context.sync();

        if (documentTables.items.length === 0) {
          console.log('No tables found in the document.');
          return; // Exit if no tables are found
        }

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

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

        firstTable.load("rows/cells/shadingColor");
        await context.sync();

        const shadingData = firstTable.rows.items.map((row: any) => {
          return row.cells.items.map((cell: any) => cell.shadingColor);
        });

        console.log("First Table Shading colors:", shadingData);
      });
    }

    // Call the function
    loadFirstTableFontColors().catch((error) => {
      console.error("Error loading shading colors:", error);
      if (error instanceof OfficeExtension.Error) {
        console.error(`Debug info: ${JSON.stringify(error.debugInfo)}`);
      }
    });
JHJ-MS commented 3 months ago

Hi @punyakrishna, I could not reproduce this issue on my Word using your attached document if you mean the first cell's shadingColor doesn't return "#000000". The .xml of your attached document includes the shading tag as expected (It is showing as follows). image image

Have you encountered this problem in other documents? Could you try to set the shading to another color to see whether the issue occurs? How about inserting another table and checking whether the issue occurs for the second table?

I guess something wrong with your document and it breaks the document's xml. The shadingColor API result aligns with the document' Xml is the design.

punyakrishna commented 2 months ago

Thank you for the response. I've reviewed the provided document and code, and I am still encountering the issue. Specifically, while you mentioned the shd tag is present, I am referring to the first row, first cell where the shd tag is missing.

Your screenshot highlights the shd tag in the first row, second cell, but my issue is specifically about the absence of the shd tag in the first row, first cell, which is resulting in an empty string being returned for the shading color.

Here is what I have done so far: Downloaded the document and code from above. Ran the code and checked the XML for the first row, first cell. The shd tag is not present in the first row, first cell, leading to the issue of receiving an empty string for the shading color.

Additionally, you suggested changing the color and checking, but my requirement is to retain the same color. Changing the color is not a viable solution for my use case, as I need to work with the existing color without altering it. Could you please verify the presence of the shd tag in the first row, first cell on your end? Thank you for your assistance.

Screenshots: image

image

JHJ-MS commented 2 months ago

Hi @punyakrishna . I confirmed that in the xml the first cell's shading tab is missing. However, I still could repro the issue of the API. You can see it in the console log in my first screenshot.

I have tired to use a new doc, and set the shading of the table from UI. Both the API result and the shading tag in xml are as expected. To help me repro the API issue. Could you describe how you set the table's shading? Do you use JS API or UI? Could you provide the code snippet if you use JS API?

microsoft-github-policy-service[bot] commented 1 month ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

microsoft-github-policy-service[bot] commented 1 month ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.