• 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");
  • 相关阅读:
    字符编码
    python基础5
    python基础4
    python基础3
    python基础2
    一、计算机基础
    Django中间件
    Django Form表单组件
    django简介,安装,文件介绍,三板斧(render,HttpResponse,redirect)HTTP协议,用socket实现简单版web框架,用wsgiref,jinja2,pymysql实现Django运行流程
    css,浮动,清浮动,溢出overflow,定位,圆形,透明度,z-index
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/10577830.html
Copyright © 2020-2023  润新知