<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. 【推荐】全球最全面的Telegram组群频道的集合网站 持续收集中

    全球最全面的Telegram组群频道的集合网站 https://www.telegramgroup.org Telegram 组群频道分享 可搜索自己想找的组群频道 从小白到大神,一个 telegra ...

  2. odoo10学习笔记十二:web controller

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11189332.html 一:路由 odoo.http.route(route=None, **kw) 装饰器 ...

  3. springcloud学习之路: (三) springcloud集成Zuul网关

    网关就是做一下过滤或拦截操作 让我们的服务更加安全 用户访问我们服务的时候就要先通过网关 然后再由网关转发到我们的微服务 1. 新建一个网关服务Module 2. 依然选择springboot工程 3 ...

  4. Rust中的模块及私有性控制

    好像没有其它语言的private, protected关键字,应了一个public关键字. mod plant { pub struct Vegetable { pub name: String, _ ...

  5. JS高阶---作用域与执行上下文

    一句话介绍 .

  6. 201871010107-公海瑜《面向对象程序设计(java)》第十二周学习总结

    201871010107-公海瑜<面向对象程序设计(java)>第十二周学习总结              项目                                内容     ...

  7. (day47)作业

    一.链式表达式完成菜单栏 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  8. 用NABCD法提出靠谱的项目建议

    在项目中提出靠谱的建议,一方面能提高项目成功的概率,另一方面锻炼自己能力提升自己在项目中的影响力,所以我们要尽可能抓住机会在项目中提建议.那要如何提出靠谱的建议呢?从需求出发,明确做法和好处,分析竞争 ...

  9. 在 Asp.Net Core 中安装 MVC

    在 ASP.NET Core 中安装 MVC 到目前为止,我们在本系列视频中使用的 ASP.NET Core 项目是使用“空”项目模板生成的.目前这个项目没有设置和安装 MVC. 两个步骤学会在 AS ...

  10. B1047 编程团体赛 (20 分)

    一.参考代码 #include<iostream> #include<cstring> using namespace std; int hashTable[1010]; in ...