问题描述:
可视化效果
Excel导出效果
解决方法:
/*
引用
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
数据
List<string> xList = new List<string>() { };
List<int> bCount = new List<int>() { };
List<int> lCount = new List<int>() { };
List<int> dCount = new List<int>() { };
List<int> dayCount = new List<int>() { };
*/
#region 导出excel
workbook = new XSSFWorkbook();
ISheet sheet = null;
fileName = savePath +strCN+strMDMC + dtpTime1 + "至" + dtpTime2 + ".xlsx";
fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
int i = 0;
try
{
sheet = workbook.CreateSheet("Sheet0");
//{"交易日期","早餐","午餐","晚餐","总数"};
IRow rowDate = sheet.CreateRow(0);
IRow rowBCount = sheet.CreateRow(1);
IRow rowLCount = sheet.CreateRow(2);
IRow rowDCount = sheet.CreateRow(3);
IRow rowAllCount = sheet.CreateRow(4);
rowDate.CreateCell(0).SetCellValue("交易日期");
rowBCount.CreateCell(0).SetCellValue("早餐");
rowLCount.CreateCell(0).SetCellValue("午餐");
rowDCount.CreateCell(0).SetCellValue("晚餐");
rowAllCount.CreateCell(0).SetCellValue("总数");
for (i = 1; i < xCount + 1;i++ )
{
rowDate.CreateCell(i).SetCellValue(xList[i-1]);
rowBCount.CreateCell(i).SetCellValue(bCount[i-1]);
rowLCount.CreateCell(i).SetCellValue(lCount[i-1]);
rowDCount.CreateCell(i).SetCellValue(dCount[i-1]);
rowAllCount.CreateCell(i).SetCellValue(dayCount[i-1]);
}
workbook.Write(fs); //写入到excel
MessageBox.Show("导出成功!");
}
catch (Exception ex)
{
MessageBox.Show("导出失败!详情联系开发者!");
}
依赖: