HSSFWorkbook workbook = null;
string FileName = @"D:\XX\CN\" + datetime + ".xls";
using (FileStream fs = File.Open(FileName ,FileMode.Open, FileAccess.Read))
{
workbook = new HSSFWorkbook(fs);
ISheet sheet = null;
sheet = workbook.GetSheetAt(0);
IRow row = null;
int rowCount = sheet.LastRowNum + 1;
foreach (var item in records)
{
row = sheet.CreateRow(rowCount);
row.CreateCell(0).SetCellValue(item.StationId);
row.CreateCell(1).SetCellValue(item.DataBatchId);
row.CreateCell(2).SetCellValue(item.CustomerId);
row.CreateCell(3).SetCellValue(item.SKU);
row.CreateCell(4).SetCellValue(item.TraceCode);
row.CreateCell(5).SetCellValue(item.DataKey);
row.CreateCell(6).SetCellValue(item.DataValue);
row.CreateCell(7).SetCellValue(item.CreatedDate);
rowCount++;
}
sheet.ForceFormulaRecalculation = true;
using (FileStream filess = File.OpenWrite(FileName))
{
workbook.Write(filess);
}
MessageBox.Show("汇出成功!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
---------------------
作者:最讨厌取昵称了
来源:优快云
原文:https://blog.youkuaiyun.com/wsx5edc/article/details/79156364
版权声明:本文为博主原创文章,转载请附上博文链接!