【发布时间】:2020-12-11 11:27:23
【问题描述】:
如何使用 C# NPOI 将单元格颜色设置为自定义颜色? 我知道如何使用颜色索引更改带有 NPOI 的单元格的颜色:
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;
但是,我想使用自定义颜色。 IndexedColors 是有限的,没有那么有用。 我已经四处寻找答案了。
几年前我发现了这个post,但它似乎不再相关。 SetFillForegroundColor 现在是短的,不再是 XSSFColor。
byte[] rgb = new byte[3] { 192, 0, 0 };
XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(rgb));
【问题讨论】:
标签: c# apache-poi npoi