<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. [PHP] 使用ftell和fseek函数直接定位文件位置获取部分数据

    对于大文件只获取部分数据很有用 1.使用ftell函数可以获取当前指针的字节位置2.使用fseek函数可以直接定位到指定的位置3.读取指定字节的数据就可以部分获取文件内容了 <?php clas ...

  2. (八)OpenStack---M版---双节点搭建---Cinder安装和配置

    ↓↓↓↓↓↓↓↓视频已上线B站↓↓↓↓↓↓↓↓ >>>>>>传送门 1.创建数据库并授权 2.获得admin凭证执行管理员命令并创建服务证书 3.创建块存储设备AP ...

  3. day32_8_14 并发编程三 线程的GIL

    一.GIL 什么是GIL? GIL是一个全局排他锁,简单来说就是为了防止多线程并行操作的锁.这里有官方解释: In CPython, the global interpreter lock, or G ...

  4. 20191003 「HZOJ NOIP2019 Round #8」20191003模拟

    综述 试题为常州集训2019SCDay2 得分\(100+30(0)+28\) 时之终结 问题描述 HZOJ1310 题解 构造题. 发现部分分有一档是 \(Y\) 是 \(2^x\) ,于是自然想到 ...

  5. spring中@Param和mybatis中@Param使用区别(暂时还没接触)

    1.spring中@Param(org.springframework.data.repository.query.Param) int selectRoleCount(@Param("bu ...

  6. ESP8266 AT指令开发(基于STC89C52单片机): 硬件使用说明

    实物图 硬件说明 开发板板载说明: 1.主控芯片: STC89C52 2.Wi-Fi模块: ESP8266 3.温湿度传感器: DHT11 4.液晶屏: IIC OLED 5.继电器: 220V 10 ...

  7. SCITE设置修改说明

    SCITE设置修改说明选项→打开全局设置文件:1.启动时最大化:position.width=-1position.height=-12.用于中文系统,要修改语言.code.page=936outpu ...

  8. Linux性能优化实战学习笔记:第二十五讲

    一.磁盘性能指标 1.使用率 2.饱和度 3.IOPS 4.吞吐量 5.响应时间 6.性能测试工具 二.磁盘I/O观测 1.每块磁盘的使用率(指标实际上来自/proc/diskstats) [root ...

  9. Redis数据结构及常用命令(草稿)

    通用命令 数据类型 string 字符 list 列表 set 集合 zset 有序集合 hash 散列(字典中的字典) bitmap 位图 hyperloglog

  10. python 利用淘宝IP库 查询IP归属地

    #coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...