Page 1 of 1

NPOI: Setzen Sie die Zellfarbe auf eine benutzerdefinierte Farbe

Posted: 13 Feb 2025, 22:47
by Anonymous
Wie setzen Sie die Zellfarbe mit C# npoi auf eine benutzerdefinierte Farbe ein?

Code: Select all

XSSFCellStyle cellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
cellStyle.FillBackgroundColor = IndexedColors.LightCornflowerBlue.Index;
cellStyle.FillForegroundColor = IndexedColors.LightCornflowerBlue.Index;
cellStyle.FillPattern = FillPattern.SolidForeground;
ICell cell = CurrentRow.CreateCell(CellIndex);
cell.CellStyle = cellStyle;
< /code>
Ich möchte jedoch eine benutzerdefinierte Farbe verwenden. Die IndexedColors sind begrenzt und nicht so nützlich. Ab vor Jahren, aber es scheint nicht mehr relevant zu sein. SetFillforegroundColor ist jetzt kurz und nicht mehr XSSFColor. < /P>
byte[] rgb = new byte[3] { 192, 0, 0 };
XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(rgb));