zoukankan      html  css  js  c++  java
  • excel 拆分多个excel并保持

    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);
    }
    }

  • 相关阅读:
    用指针写线段树(维护乘法)
    费用流——网络流板子
    最小割板子题——[USACO5.4]奶牛的电信
    数论——置换
    NOIP2012 借教室
    POJ1990 moofest
    POJ2352 star
    POJ2299 Ultra-QuickSort
    CF498D Traffic Jams in the land
    POJ2828 Buy Ticket
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/12169590.html
Copyright © 2011-2022 走看看