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

Black background when using shading option in tables. #3008

Open
Vaibhav91one opened this issue Mar 21, 2025 · 0 comments
Open

Black background when using shading option in tables. #3008

Vaibhav91one opened this issue Mar 21, 2025 · 0 comments

Comments

@Vaibhav91one
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant