1、安装引用DotNetCore.NPOI
1)使用Nuget界面管理器
搜索"DotNetCore.NPOI"
,在列表中找到它,点击"安装"
相关文档:VS(Visual Studio)中Nuget的使用
2)使用Package Manager命令安装
PM> Install-Package DotNetCore.NPOI
3)使用.NET CLI命令安装
> dotnet add TodoApi.csproj package DotNetCore.NPOI
2、使用NPOI设置Excel的单元格背景颜色
命名空间:
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
示例代码:
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.GetSheet("Sheet1");
IRow row = sheet.CreateRow(0);
//styling
IFont boldFont = workbook.CreateFont();
boldFont.Boldweight = (short)FontBoldWeight.Bold;
ICellStyle boldStyle = workbook.CreateCellStyle();
boldStyle.SetFont(boldFont);
boldStyle.BorderBottom = BorderStyle.Medium;
boldStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
boldStyle.FillPattern = FillPattern.SolidForeground;
ICell cell = row.CreateCell(5);
cell.SetCellValue("cjavapy");
cell.CellStyle = boldStyle;