博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 动态导出excel表单 无模板文件下载
阅读量:3965 次
发布时间:2019-05-24

本文共 1803 字,大约阅读时间需要 6 分钟。

java 动态导出excel表单 无模板文件下载

public ResponseEntity
exportStanding(@PathVariable Long signupId) throws IOException { MettingSignup mettingSignup = mettingSignupService.getById(signupId); Meeting meeting = meetingService.getById(mettingSignup.getMeetingId()); List
> mapLists = signupUserinfoService.selectBySignupId(signupId,1,1000); //上面是获取数据,根据自己不同需求去获取不同数据 // 创建工作薄 HSSFWorkbook workbook = new HSSFWorkbook(); // 创建用户工作表 HSSFSheet sheet = workbook.createSheet("报名用户"); //创建行 HSSFRow rows = sheet.createRow(0); // 动态添加 表头 headList --> 所有表头行集合 List
> headList = new ArrayList
>(); List
mapList = formTemplateService.selectFormTitleBySignupId(signupId); // 第 n 行 的表头 int j=0; for (Map map:mapList) { //创建列 rows.createCell(j).setCellValue((String) map.get("form_title")); j++; } j=1; // 第 n 行的数据 for (Map
maps : mapLists) { HSSFRow rowss = sheet.createRow(j); int i=0; for (Map map:mapList) { //创建列 rowss.createCell(i).setCellValue((String)maps.get(map.get("form_title"))); i++; } j++; } //字节输出流 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } finally { outputStream.close(); } //http请求头 HttpHeaders httpHeaders = new HttpHeaders(); String name = meeting.getName()+".xls"; String fileName = new String(name.getBytes("UTF-8"), "iso-8859-1"); //设置内容属性 httpHeaders.setContentDispositionFormData("attachment", fileName); httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); ResponseEntity
filebyte = new ResponseEntity
(outputStream.toByteArray(), httpHeaders, HttpStatus.CREATED); try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } finally { outputStream.close(); } return filebyte;}

转载地址:http://kjyki.baihongyu.com/

你可能感兴趣的文章
SQLServer
查看>>
Hibernate 通过 Hibernate 访问数据库
查看>>
java面试题
查看>>
消息队列相关(MQ)
查看>>
生成短连接
查看>>
java多线程
查看>>
mybatis高级结果映射
查看>>
java 中的锁
查看>>
线程池
查看>>
深入浅出:Tomcat应用服器中Servlet容器架构及工作原理剖析
查看>>
fastjson 将json和java对象相互转换
查看>>
java获取cookie
查看>>
kafaka用例&市上最全总结
查看>>
神器 PySimpleGUI 初体验
查看>>
编程 学习视频教程大全
查看>>
查找最快的docker镜像
查看>>
AssignProcessToJobObject 错误码5 的解决办法
查看>>
windows LibreOffice 6.3.5 安装出错1355 问题解决
查看>>
libreoffice/openoffice c/c++转换office格式为pdf
查看>>
Tomcat 7.0 64位免安装解压版 安装及配置
查看>>