zoukankan      html  css  js  c++  java
  • NPOI导出信息

    public ActionResult ExportInfo(ProjectSearch projectWhere)
            {
                HSSFWorkbook hssfworkbook = new HSSFWorkbook();
    
                #region 定义excel表格
                ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
                IRow row1 = sheet1.CreateRow(0);
                row1.CreateCell(0).SetCellValue("姓名");
                row1.CreateCell(1).SetCellValue("身份证号");
                #endregion
    
                #region 填充数据
                int rownum = 1;
                long total = 0;var list = new List<Project>();//假装有数据
                var sheetIndex = 1;
                foreach (Project model in list)
                {
                    //如果行数超过了excel最大限制,创建新sheet
                    if ((rownum + 1) % 65535 == 0)
                    {
                        sheet1 = hssfworkbook.CreateSheet("Sheet" + (++sheetIndex));
                        IRow row0 = sheet1.CreateRow(0);
                        row0.CreateCell(0).SetCellValue("姓名");
                        row0.CreateCell(1).SetCellValue("身份证号");
                        rownum = 1;
                        sheetIndex++;
                    }
                    IRow row3 = sheet1.CreateRow(rownum);
                    row3.CreateCell(0).SetCellValue(model.Name);
                    row3.CreateCell(1).SetCellValue(model.PersonalId);
                    rownum++;
                }
    
                #endregion
    
                string folder = Server.MapPath("/Down/");
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                //写入到表格
                string filename2 = "信息" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                using (FileStream fs = new FileStream(folder + filename2, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    hssfworkbook.Write(fs);
                }
    
                string url = "../Down/" + filename2;
                return Json(new { result = true, url = url });
            }    
  • 相关阅读:
    SwiftUI:看我展示52张扑克牌,“很快啊!”
    不会吧,这也行?iOS后台锁屏监听摇一摇
    分布式锁
    布隆过滤器原理
    redis缓存穿透
    布隆过滤器应用DEMO
    线程的声明周期
    分布式事务
    滑动窗口协议
    代理
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/14096238.html
Copyright © 2011-2022 走看看