NPOI 自定义单元格背景颜色

首先,单元格背景颜色的Style里面的属性不是"FillBackgroundColor",正确的应该是FillForegroundColor。 其次我们不仅仅需要设置颜色,而且还要设置该style的FillPattern。 下面是代码:

1
2
3
4
ICellStyle style = workbook.CreateCellStyle();
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
style.FillPattern = FillPattern.SolidForeground;
ICell cell = workbook.CreateSheet().CreateRow(0).CreateCell(0);cell.CellStyle = style;
Built with Hugo
主题 StackJimmy 设计