C#使用NPOI导出excel设置单元格背景颜色

ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.FillPattern = FillPattern.SolidForeground;
cellStyle.FillForegroundColor = 47;
cell.CellStyle = cellStyle;

在设置FillForegroundColor的同时需要设置FillPattern。

FillForegroundColor接收的事一个short类型的值,每个颜色对应的值可以在网上搜一下找到。

原文地址:https://www.cnblogs.com/blazeZzz/p/9129312.html