后台数据转换成Excel,前台下载
<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,前台下载的更多相关文章
- 关于jsp页面转换成excel格式下载遇到问题及解决
jsp页面转成excel格式的实现思路: 1.使用poi包:poi-bin-3.9-20121203 下载连接地址:http://www.apache.org/dyn/closer.cgi/poi/r ...
- vue 把后台返回的json拼接成excel并下载
先封装一下生成excel的方法 downfile.js export default { data() { return {} }, components: {}, created() { }, me ...
- Java将TXT上的数据转换成excel里面
package test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...
- Datatable数据转换成excel导出时 数值类型在EXCEL中为文本形式 无法进行统计
功能背景 有地税上以及各企业的一个缴费情况的比对,基于两表进行匹配查看数据是否在合理范围内,对比对完成表进行数值导出. 2.问题描述 匹配和生成匹配结果导出已成功完成,但是在数值列导出后变成了文本形式 ...
- SpringMVC系列(十一)把后台返回的数据转换成json、文件下载、文件上传
一.后台返回的数据转换成json 1.引入转换json需要的3个依赖 <!--json转换需要的依赖 begin --> <dependency> <groupId> ...
- 将Excel表格数据转换成Datatable
/// <summary> /// 将Excel表格数据转换成Datatable /// </summary> /// <param name="fileUrl ...
- 使用js将后台返回的数据转换成树形结构
将类似如下数据转换成树形的数据: [ { id: 1, name: '1', }, { id: 2, name: '1-1', parentId: 1 }, { id: 3, name: '1-1-1 ...
- Web Api 将DataTable装换成Excel,并通过文件流将其下载
不废话,直接上代码 前端代码 <input type="button" class="layui-btn" value="Test-GetFil ...
- MVC 将视图页table导出成excel
前台代码: <table class="tablelist" id="myTable"> <thead> <t ...
随机推荐
- Nginx配置实验反向代理
l 实验要求 浏览器访问 8083.mine.com:8081 地址,(Nginx端口是8081)通过Nginx服务器反向代理监听请求,将请求转发到tomcat服务器上,实现真正内容的访问. l ...
- jQuery的animate
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Django Form 初始化数据
修改 urls.py 添加 path('initial.html', views.initial), 修改 models.py class UserInfo(models.Model): name = ...
- 使用BurpSuite做中转代理时候出现Failed to connect to www.xxx.com:443 的时候可能原因
1.可能是BurpSuite没有设置好代理,需要BurpSuite需要进行设置如下图:
- 01-MySQL 大纲介绍
MySQL 大纲介绍 1.官方定义的MySQL DBA工作内容 (1)运维DBA 初级:各版本.各平台安装搭建.升级 中级:体系结构原理.基础管理(启动关闭.初始化配置文件管理.多实例管理.用户权限管 ...
- Truck History POJ - 1789
题目链接:https://vjudge.net/problem/POJ-1789 思路: 题目意思就是说,给定一些长度为7的字符串,可以把字符串抽象为一个点, 每个点之间的距离就是他们本身字符串与其他 ...
- CMS收集器和G1收集器 他们的优缺点对比 G1只有并发标记才不会stop-the-world 其他都会停下来(阿里多次问到)
CMS收集算法 参考:图解 CMS 垃圾回收机制原理,-阿里面试题 G1收集算法 参考:G1 垃圾收集器入门 首先要知道 Stop the world的含义(网易面试):不管选择哪种GC算法,stop ...
- web框架--tornado框架之模板引擎
使用Tornado实现一个简陋的任务表功能demo来讲解tornado框架模板引擎 一.demo目录结构 二.具体文件内容 2.1.commons.css .body{ margin: 0; back ...
- [LeetCode] 44. Wildcard Matching 外卡匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- map、set 使用方法 | 1022 图书馆信息查询
看了答案才知道了这题的各种骚操作,然后敲了一顿骚键盘,然后wa.调了很久,才发现要规格化打印……mdzz…… 注:加粗代码为傻逼规格化打印代码: #include <stdio.h> #i ...