说明:
需要引用NPOI包可使用NuGet下载安装或根据提示安装NPOI包
导出方法:
/// <summary>
/// 导出数据
/// </summary>
/// <param name="list"></param>数据源
/// <param name="path"></param>文件目录
/// <param name="fileName"></param>文件名
public static bool ExPort(List<ExportEntity> list, string path, string fileName)
{
XSSFWorkbook workBook = new XSSFWorkbook(); //实例化XSSF
ICellStyle cellStyle = workBook.CreateCellStyle();
cellStyle.FillPattern = FillPattern.SolidForeground;
cellStyle.FillForegroundColor = 10; //单元格格背景色
XSSFSheet sheet = (XSSFSheet)workBook.CreateSheet(); //创建一个sheet
//添加表头
IRow frow0 = sheet.CreateRow(0); // 添加一行(一般第一行是表头)
frow0.CreateCell(0).SetCellValue("第一列");
frow0.Create