<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
/**
* 打印考生成绩
* @return
*/
@RequestMapping("/getExamScore")
public void downloadExamScore(HttpServletResponse response, HttpSession httpSession) throws IOException {
String ordId = (String) httpSession.getAttribute("ordId");
//声明一个工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
//声明一个表格
HSSFSheet sheet = workbook.createSheet("成绩表");
//设置表格的默认宽度
sheet.setDefaultColumnWidth((short) 30);
//需要打印的信息
List<ExamScoreView> examScoreList = examSeatService.getExamScore(ordId);
//需要导出文件的名字
String fileName = "成绩表" + ".xls";
int rowNum = 1;
//导出Excel表格头部
String[] headers = {"学员姓名", "学员身份证号", "性别", "学历", "工作单位", "手机号", "邮箱", "单位电话", "单位地址", "健康状况", "身份证件类型"
, "初(复)训", "学员标识", "所属班级", "是否补考", "预约考试地点", "单位电话", "考试申请记录标识", "考试场次标识", "阅卷人", "得分", "是否合格", "准考证id"
, "考试类别编号", "准考证号", "考点编号", "考点地址", "考试时间", "考试类别名称", "教室编号"
, "机位号", "机位编号", "考场名称", "负责人名字", "负责人电话", "负责人邮箱", "开始考试时间", "结束考试时间", "场次编号", "操作类型"};
HSSFRow row = sheet.createRow(0);
//在Excel中添加表头
for (int i = 0; i < headers.length; i++) {
HSSFCell cell = row.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text);
}
//在表中存放查询到的数据放入对应的列
for (ExamScoreView examScoreView : examScoreList) {
HSSFRow row1 = sheet.createRow(rowNum);
row1.createCell(0).setCellValue(examScoreView.getStuName());
row1.createCell(1).setCellValue(examScoreView.getStuCardId());
row1.createCell(2).setCellValue(examScoreView.getGender());
row1.createCell(3).setCellValue(examScoreView.getEduCode());
row1.createCell(4).setCellValue(examScoreView.getWorkUnit());
row1.createCell(5).setCellValue(examScoreView.getPhon());
row1.createCell(6).setCellValue(examScoreView.getEmail());
row1.createCell(7).setCellValue(examScoreView.getUnitPhon());
row1.createCell(8).setCellValue(examScoreView.getUnitAddr());
row1.createCell(9).setCellValue(examScoreView.getHealth());
row1.createCell(10).setCellValue(examScoreView.getStuCardType());
row1.createCell(11).setCellValue(examScoreView.getFrCode());
row1.createCell(12).setCellValue(examScoreView.getsId());
row1.createCell(13).setCellValue(examScoreView.getClassId());
row1.createCell(14).setCellValue(examScoreView.getIsMakeup());
row1.createCell(15).setCellValue(examScoreView.getAplyAddress());
row1.createCell(16).setCellValue(examScoreView.getUnitPost());
row1.createCell(17).setCellValue(examScoreView.getAplyId());
row1.createCell(18).setCellValue(examScoreView.getOrdId());
row1.createCell(19).setCellValue(examScoreView.getExamInesName());
row1.createCell(20).setCellValue(examScoreView.getScore());
row1.createCell(21).setCellValue(examScoreView.getIsPass());
row1.createCell(22).setCellValue(examScoreView.getAdmId());
row1.createCell(23).setCellValue(examScoreView.getcId());
row1.createCell(24).setCellValue(examScoreView.getAdmNo());
row1.createCell(25).setCellValue(examScoreView.getSiteId());
row1.createCell(26).setCellValue(examScoreView.getTestsitesAddress());
row1.createCell(27).setCellValue(examScoreView.getExamTypeName());
row1.createCell(28).setCellValue(examScoreView.getRoomId());
row1.createCell(29).setCellValue(examScoreView.getSeatNo());
row1.createCell(30).setCellValue(examScoreView.getSeatCode());
row1.createCell(31).setCellValue(examScoreView.getRoomName());
row1.createCell(32).setCellValue(examScoreView.getPersonName());
row1.createCell(33).setCellValue(examScoreView.getPersonMobile());
row1.createCell(34).setCellValue(examScoreView.getPersonEmail());
row1.createCell(35).setCellValue(examScoreView.getOrdTime());
row1.createCell(36).setCellValue(examScoreView.getOrdEndTime());
row1.createCell(37).setCellValue(examScoreView.getOrdNo());
row1.createCell(38).setCellValue(examScoreView.getOpType());
rowNum++;
}
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=" +java.net.URLEncoder.encode(fileName, "UTF-8"));
    response.flushBuffer();
workbook.write(response.getOutputStream());
}

后台数据转换成Excel,前台下载的更多相关文章

  1. 关于jsp页面转换成excel格式下载遇到问题及解决

    jsp页面转成excel格式的实现思路: 1.使用poi包:poi-bin-3.9-20121203 下载连接地址:http://www.apache.org/dyn/closer.cgi/poi/r ...

  2. vue 把后台返回的json拼接成excel并下载

    先封装一下生成excel的方法 downfile.js export default { data() { return {} }, components: {}, created() { }, me ...

  3. Java将TXT上的数据转换成excel里面

    package test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...

  4. Datatable数据转换成excel导出时 数值类型在EXCEL中为文本形式 无法进行统计

    功能背景 有地税上以及各企业的一个缴费情况的比对,基于两表进行匹配查看数据是否在合理范围内,对比对完成表进行数值导出. 2.问题描述 匹配和生成匹配结果导出已成功完成,但是在数值列导出后变成了文本形式 ...

  5. SpringMVC系列(十一)把后台返回的数据转换成json、文件下载、文件上传

    一.后台返回的数据转换成json 1.引入转换json需要的3个依赖 <!--json转换需要的依赖 begin --> <dependency> <groupId> ...

  6. 将Excel表格数据转换成Datatable

    /// <summary> /// 将Excel表格数据转换成Datatable /// </summary> /// <param name="fileUrl ...

  7. 使用js将后台返回的数据转换成树形结构

    将类似如下数据转换成树形的数据: [ { id: 1, name: '1', }, { id: 2, name: '1-1', parentId: 1 }, { id: 3, name: '1-1-1 ...

  8. Web Api 将DataTable装换成Excel,并通过文件流将其下载

    不废话,直接上代码 前端代码 <input type="button" class="layui-btn" value="Test-GetFil ...

  9. MVC 将视图页table导出成excel

    前台代码: <table class="tablelist" id="myTable">    <thead>        <t ...

随机推荐

  1. jar 冲突、class 冲突的检测脚本

    思路很简单,解开war包,解开 jar 包,发现有同名 package.class 就报出来,不管是否“兼容” .. import zipfile import io from collections ...

  2. 获取List<object>中对象的属性值

    List<object> ls = new List<object>(); ls.Add(,name="sqm"}); ls.Add(,name=" ...

  3. kibana和中文分词器analysis-ik的安装使用

    Centos7安装elasticSearch6 上面讲述了elasticSearch6的安装和使用教程. 下面讲一下elasticsearch6的管理工具Kibana. Kibana是一个开源的分析和 ...

  4. 4-7 3D绘图

    In [1]: import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D % ...

  5. CnetOS6.7编译安装MariaDB

    --安装所需软件包 [root@localhost mariadb-10.1.14]# yum install bison bison-devel ncurses libxml2 libxml2-de ...

  6. 2.4 Scala函数式编程

    一.函数定义与使用 1.函数的定义 2.匿名函数 举例: Scala自动推断变量类型,不用声明: 一个下划线只能表示这一个参数的一次出现 二.高阶函数 定义:函数定义的括号里仍然是个函数的函数,叫作高 ...

  7. 如果使用jsp文件,需要在配置文件中配置resources项,才能让idea识别这个jsp文件

    没有添加这一项在编译后的.class文件中的结构目录是这样子的 添加上这一个配置项,在class配置文件中的位置是这样子的: 添加的配置文件是这样子的: <resources> <r ...

  8. ssh登录缓慢,输入账户密码等待时间长

    vim /etc/ssh/sshd_config #取消ssh的反向dns解析 UseDNS no #关闭ssh的gssapi认证 GSSAPIAuthentication no #排查是否日志文件过 ...

  9. 201871010114-李岩松《面向对象程序设计(java)》第十三周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  10. 201871010109-胡欢欢《面向对象程序设计(java)》第十二周学习总结

    201871010109-胡欢欢<面向对象程序设计(java)>第十二周学习总结   内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这 ...