HSSFWorkbook hssfWorkbook = null;
using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
{
hssfWorkbook = new HSSFWorkbook(file);
}
List<SupplierLogistics> logistics = new List<SupplierLogistics>();
List<string> err_log = new List<string>();//错误日志
ICell tempCell = null;
ISheet sheet = hssfWorkbook.GetSheetAt(0);
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
int rowIndex = 0;
string shipping_company_code = string.Empty;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn(“test”));

while (rows.MoveNext())
{
DataRow dr = dt.NewRow();
rowIndex++;
//if (1 == rowIndex)
//{
// continue;
//}
StringBuilder sb = new StringBuilder();
HSSFRow row = (HSSFRow)rows.Current;

tempCell = row.GetCell(0);
dr[“test”] = tempCell.ToString();
dt.Rows.Add(dr);
if (rowIndex == 2000)
{
list.Add(dt);
rowIndex = 0;
dt = new DataTable();
dt.Columns.Add(“test”);
}
}
list.Add(dt);

for (int i = 0;i< list.Count; i++)
{

NPOI.HSSF.UserModel.HSSFWorkbook workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();
NPOIHelper.CreateExcel(out workbook, list[i], new string[] { “昵称” });
using (FileStream file = new FileStream(PageHelper.ServerPath + DateTime.Now.ToString(“yyyyMMdd”) + i + “.xls”, FileMode.Create))
{
workbook.Write(file);
}
}

版权声明:本文为muxueyuan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/muxueyuan/p/12169590.html