//创建工作簿对象
IWorkbook workbook = new HSSFWorkbook();
//创建工作表
ISheet sheet = workbook.CreateSheet("onesheet");
IRow row0 = sheet.CreateRow(0);
row0.CreateCell(0).SetCellValue("ProductName");
row0.CreateCell(1).SetCellValue("AKSItem");
row0.CreateCell(2).SetCellValue("Model");
row0.CreateCell(3).SetCellValue("Cost");
row0.CreateCell(4).SetCellValue("Price");
row0.CreateCell(5).SetCellValue("Qty");
row0.CreateCell(6).SetCellValue("SalesHistory");
row0.CreateCell(7).SetCellValue("DaysRemaining");
for (int r = 1; r < suppliers.Count; r++)
{
//创建行row
IRow row = sheet.CreateRow(r);
row.CreateCell(0).SetCellValue(suppliers[r].ProductName);
row.CreateCell(1).SetCellValue(suppliers[r].AKSItem);
row.CreateCell(2).SetCellValue(suppliers[r].Model);
row.CreateCell(3).SetCellValue(suppliers[r].Cost);
row.CreateCell(4).SetCellValue(suppliers[r].Price);
row.CreateCell(5).SetCellValue(suppliers[r].Qty);
row.CreateCell(6).SetCellValue(suppliers[r].SalesHistory);
row.CreateCell(7).SetCellValue(suppliers[r].DaysRemaining);
}
//创建流对象并设置存储Excel文件的路径
using (FileStream url = File.OpenWrite(@"C:\Users\Administrator\Desktop\数据采集.xls"))
{
//导出Excel文件
workbook.Write(url);
Console.WriteLine("<script>alert('写入成功!')</script>");
};
.net list导出到excel
最新推荐文章于 2023-07-08 10:36:57 发布