Skip to content

Black background when using shading option in tables. #3008

Open
@Vaibhav91one

Description

@Vaibhav91one

I am having this issue the shading works everywhere properly but when I am opening the docx in word on my system. For some reason the color's of the shading are turning black. Please find below the code and POC.

return new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: [
      // ✅ Header Row
      new TableRow({
        children: [
          createStyledTableCell_legend("Severity Level", "FFFFFF", "0B3D91"), // Dark Blue Background
          createStyledTableCell_legend("Severity Number", "FFFFFF", "0B3D91"), // Dark Gray Background
          createStyledTableCell_legend("Explanation", "FFFFFF", "0B3D91"), // Dark Blue Background
        ],
      }),

      // ✅ Data Rows
      ...severityLevels.map(
        (severity) =>
          new TableRow({
            children: [
              createSeverityCell(severity.level), // Severity Level with background color
              createTableCell_legend(severity.sev, AlignmentType.CENTER), // Severity Number
              createTableCell_legend(severity.explanation), // Explanation
            ],
          })
      ),
    ],
  });
};

// ✅ Function to create header cells with background color
const createStyledTableCell_legend = (
  text: string,
  color: string,
  bgColor: string
) => {
  return new TableCell({
    children: [
      new Paragraph({
        children: [new TextRun({ text, bold: true, color, font: "Helvetica" })],
        alignment: AlignmentType.CENTER,
      }),
    ],
    shading: { type: ShadingType.SOLID, fill: bgColor },
  });
};

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions