zoukankan      html  css  js  c++  java
  • NPOI导出Excel

      var list = vM_VolunteerBLL.GetVM_VolunteerList(where);
                IWorkbook work =new XSSFWorkbook();
                ISheet sheet = work.CreateSheet("志愿者信息表");
                IRow row = sheet.CreateRow(0);
                row.CreateCell(0).SetCellValue("行号");
                row.CreateCell(1).SetCellValue("姓名");
                row.CreateCell(2).SetCellValue("性别");
                row.CreateCell(3).SetCellValue("出生日期");
                row.CreateCell(4).SetCellValue("身份证");
                row.CreateCell(5).SetCellValue("护照");
                row.CreateCell(6).SetCellValue("手机");
                row.CreateCell(7).SetCellValue("邮箱");
                row.CreateCell(8).SetCellValue("国籍");
                row.CreateCell(9).SetCellValue("城市");
                row.CreateCell(10).SetCellValue("比赛名称");
                row.CreateCell(11).SetCellValue("比赛时间");
                row.CreateCell(12).SetCellValue("工作类型");
                row.CreateCell(13).SetCellValue("工作内容");
                row.CreateCell(14).SetCellValue("创建人");
                row.CreateCell(15).SetCellValue("创建时间");
                for (var i = 0; i < list.Count; i++)
                {
                    row = sheet.CreateRow(i + 1);
                    row.CreateCell(0).SetCellValue(i + 1);
                    row.CreateCell(1).SetCellValue(list[i].Name);
                    row.CreateCell(2).SetCellValue(list[i].Sex==1?"":"");
                    row.CreateCell(3).SetCellValue(list[i].Birthday.ToString("yyyy-MM-dd"));
                    row.CreateCell(4).SetCellValue(list[i].IDCard);
                    row.CreateCell(5).SetCellValue(list[i].Protection);
                    row.CreateCell(6).SetCellValue(list[i].Phone);
                    row.CreateCell(7).SetCellValue(list[i].EMail);
                    row.CreateCell(8).SetCellValue(list[i].Country);
                    row.CreateCell(9).SetCellValue(list[i].City);
                    row.CreateCell(10).SetCellValue(list[i].GameName);
                    row.CreateCell(11).SetCellValue(list[i].GameDate.ToString("yyyy-MM-dd"));
                    row.CreateCell(12).SetCellValue(list[i].VolunteerTypeName);
                    row.CreateCell(13).SetCellValue(list[i].WorkContext);
                    row.CreateCell(14).SetCellValue(list[i].CreateName);
                    row.CreateCell(15).SetCellValue(list[i].CreateDate.ToString("yyyy-MM-dd"));
                }
                //声明空的byte数组
                byte[] buffer = new byte[0];
                //创建缓存流
                using (MemoryStream ms = new MemoryStream())
                {
                    //将work写入缓存流
                    work.Write(ms);
                    buffer = ms.GetBuffer();
                }
                //返回byte数组
                return File(buffer, "application/ms-excel", "志愿者信息.xlsx");
  • 相关阅读:
    vue 进行ajax请求,使用axios
    webpack 小记
    js闭包
    git小记
    sublime text3 插件安装
    mysql安装
    四十九、django单表操作,多表操作,一对多,多对多,分组查询,聚合查询,F、Q查询,自定义char字段,事务,only与defer ,choices字段
    四十八、模板层,标签,过滤器,继承和导入
    四十七、django路由匹配,分组,反向解析,路由分发,视图层
    四十六、django配置及增删改查
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/10577830.html
Copyright © 2011-2022 走看看