Excel 导出 哪位大神有更好的可以指点一下

/**
* expressions封装的查询条件使用时可以自行修改
*
*/
@PostMapping("/reward/exportContract")public void exportContract(HttpServletResponse response, @RequestParam(name = "order") String orderBy,@JsonRequestParam(value = "exp", required = false) Expression[] expressions) throws Exception {int startPosition = 0;int maxResults = -1;//查询导出数据ListRange result = this.queryList(orderBy, startPosition, maxResults, expressions);//result转实体类数组DsznJlsqInfo[] data = (DsznJlsqInfo[]) result.getData();try {HSSFWorkbook wb = new HSSFWorkbook();//标题字体HSSFFont title_font = wb.createFont();title_font.setFontName("黑体");title_font.setFontHeightInPoints((short) 24);title_font.setBold(true);//标题样式HSSFCellStyle title_style = wb.createCellStyle();title_style.setAlignment(HorizontalAlignment.CENTER);title_style.setVerticalAlignment(VerticalAlignment.CENTER);title_style.setFont(title_font);//首行字体HSSFFont first_font = wb.createFont();first_font.setFontHeightInPoints((short) 12);first_font.setBold(true);//首行样式HSSFCellStyle first_style = wb.createCellStyle();first_style.setAlignment(HorizontalAlignment.CENTER);first_style.setVerticalAlignment(VerticalAlignment.CENTER);first_style.setFont(first_font);//数据行样式HSSFCellStyle data_style = wb.createCellStyle();data_style.setAlignment(HorizontalAlignment.CENTER);data_style.setVerticalAlignment(VerticalAlignment.CENTER);HSSFSheet sheet = wb.createSheet("表名");HSSFRow row1 = sheet.createRow(0);HSSFCell cell0 = row1.createCell(0);HSSFCell cell1 = row1.createCell(1);HSSFCell cell2 = row1.createCell(2);HSSFCell cell3 = row1.createCell(3);HSSFCell cell4 = row1.createCell(4);HSSFCell cell5 = row1.createCell(5);HSSFCell cell6 = row1.createCell(6);HSSFCell cell7 = row1.createCell(7);HSSFCell cell8 = row1.createCell(8);HSSFCell cell9 = row1.createCell(9);//列头cell0.setCellValue("序号");cell1.setCellValue("标题");cell2.setCellValue("申请人");cell3.setCellValue("身份证号");cell4.setCellValue("性别");cell5.setCellValue("联系电话");cell6.setCellValue("退休时间");cell7.setCellValue("员工类型");cell8.setCellValue("申报状态");cell9.setCellValue("申报时间");cell0.setCellStyle(first_style);cell1.setCellStyle(first_style);cell2.setCellStyle(first_style);cell3.setCellStyle(first_style);cell4.setCellStyle(first_style);cell5.setCellStyle(first_style);cell6.setCellStyle(first_style);cell7.setCellStyle(first_style);cell8.setCellStyle(first_style);cell9.setCellStyle(first_style);HSSFRow row2 = null;if (data != null) {for (int i = 0; i < data.length; i++) {DsznJlsqInfo userItem = data[i];row2 = sheet.createRow(i + 1);HSSFCell cell20 = row2.createCell(0);HSSFCell cell21 = row2.createCell(1);HSSFCell cell22 = row2.createCell(2);HSSFCell cell23 = row2.createCell(3);HSSFCell cell24 = row2.createCell(4);HSSFCell cell25 = row2.createCell(5);HSSFCell cell26 = row2.createCell(6);HSSFCell cell27 = row2.createCell(7);HSSFCell cell28 = row2.createCell(8);HSSFCell cell29 = row2.createCell(9);cell20.setCellValue((i + 1) + "");cell21.setCellValue(StringUtils.trim(userItem.getBt()));cell22.setCellValue(StringUtils.trim(userItem.getSqr()));cell23.setCellValue(StringUtils.trim(userItem.getSfzh()));//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");cell24.setCellValue(StringUtils.trim(userItem.getGender()));cell25.setCellValue(StringUtils.trim(userItem.getPhone()));cell26.setCellValue(StringUtils.trim(userItem.getTxsj()));cell27.setCellValue(StringUtils.trim(userItem.getYglx()));cell28.setCellValue(StringUtils.trim(userItem.getStatus()));cell29.setCellValue(StringUtils.trim(userItem.getSqsj()));cell20.setCellStyle(data_style);cell21.setCellStyle(data_style);cell22.setCellStyle(data_style);cell23.setCellStyle(data_style);cell24.setCellStyle(data_style);cell25.setCellStyle(data_style);cell26.setCellStyle(data_style);cell27.setCellStyle(data_style);cell28.setCellStyle(data_style);cell29.setCellStyle(data_style);}}for (int i = 0; i <= 6; i++) {sheet.autoSizeColumn(i);sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 6);}//时间我用了包装类,使用时自行设置String fileName = new String(("下载的表名-" + DF_TO_STRING.format((new Date()).getTime()) + ".xls").getBytes("gb2312"), "ISO-8859-1");//准备将Excel的输出流通过response输出到页面下载//八进制输出流response.setContentType("application/octet-stream");// 告诉浏览器用什么软件可以打开此文件response.setHeader("content-Type", "application/vnd.ms-excel");//设置导出Excel的名称response.setHeader("Content-disposition", "attachment;filename=" + fileName);//刷新缓冲response.flushBuffer();wb.write(response.getOutputStream());wb.close();} catch (Exception e) {e.printStackTrace();}}

javaExcel数据导出相关推荐

  1. WPF及Silverlight中将DataGrid数据导出

    这段源码是我在项目中实际应用的源码,没有经过删减及处理. 如果你认为有用可以摘去作为自己的导出类中的一个小工具使用. /// <summary>     /// 数据源导出辅助类      ...

  2. 百度指数常见php框架,怎么导出数据到excel表格-如何将百度指数数据导出到Excel表格...

    如何将百度指数数据导出到Excel表格 第一步:打开CAD.CAD命令行输入"Li"."选择对象"选需要提取坐标的多段线.回车. 第二步:将CAD文本框中的数据 ...

  3. mysql授权其他用户导出数据_mysql创建账号、授权、数据导出、导入

    1.账号创建及授权 grant all privileges on *.* to 'yangxin'@'%' identified by 'yangxin123456' with grant opti ...

  4. mysql excel 命令行_MySQL 命令行数据导出到 Excel

    显示行号 | 选择喜欢的代码风格 默认 GitHub Dune LakeSide Plateau Vibrant Blue Eighties Tranquil 将 MySQL 的数据导出 Excel, ...

  5. QIIME 2教程. 10数据导出ExportingData(2021.2)

    QIIME 2用户文档. 10数据导出 https://docs.qiime2.org/2021.2/tutorials/exporting/ Exporting data 注:最好按本教程顺序学习, ...

  6. QIIME 2教程. 10数据导出Exporting data(2020.11)

    文章目录 QIIME 2用户文档. 10数据导出 导出特征表 导出进化树 导出与提取 译者简介 Reference 猜你喜欢 写在后面 QIIME 2用户文档. 10数据导出 https://docs ...

  7. QIIME 2用户文档. 9数据导出Exporting data(2018.11)

    文章目录 前情提要 QIIME 2用户文档. 9数据导出 导出特征表 导出进化树 导出与提取 Reference 译者简介 猜你喜欢 写在后面 前情提要 文章导读:QIIME 2可重复.交互和扩展的微 ...

  8. pythonmysql查询转list_使用Python将Mysql的查询数据导出到文件的方法

    mysql官方提供了很多种connector,其中包括python的connector. 下载地址在:http://dev.mysql.com/downloads/connector/python/ ...

  9. oracle 数据导出

    oracle 数据导出 分类: oracle 2011-10-23 16:22 25人阅读 评论(0) 收藏 举报 方案一:使用SQLPlus的Spool命令.Spool是SQLPlus的命令,不是S ...

  10. 关于Sqlserver中 BCP命令,实现数据导出功能。

    关于Sqlserver中 BCP命令,实现数据导出功能. exec master..xp_cmdshell 'bcp "select 账号 ,姓名, 账号 from datat.dbo.个人 ...

最新文章

  1. 关于Dreamweaver乱码问题的解决方案
  2. KVM虚拟机内无agent情况下的监控方法
  3. 找出得分最高的无重复子段
  4. 线性代数知识汇总(转载)
  5. JavaScript变量声明+数据类型+数字格式+操作符+进制
  6. 数据分析工具该如何选择
  7. [转载]Unity3D 访问Access数据库
  8. 数学边界(数学萌芽、初等数学、高等数学)
  9. Music Collector Mac破解版——你身边的音乐收藏专家
  10. Java学习之基础知识2
  11. 一日一技:Python + Excel——飞速处理数据分析与处理
  12. Arduino测试一块5路非自锁开关量输入模块ardunio中断编程示例
  13. 如何高效处理面板数据
  14. 电子设计教程16:共射极放大电路
  15. Okra框架(一) 简介
  16. 解决Ubuntu 20.04挂载NTFS分区不能写入(只读权限)的问题
  17. 德克萨斯长角牛 --最短路径
  18. 苹果手机投影_智能手机投屏到投影仪
  19. python 小工具 之 房贷计算器
  20. [Python]查看Python版本

热门文章

  1. WEBPACK+ES6+REACT入门(2/7)-在项目中使用react以及JSX语法介绍
  2. android 基础布局
  3. NO.1 根据数组元素之和,获取对应索引
  4. Docker从理论到实践(七)------Docker数据管理
  5. (6)Redis的高可用方案
  6. Java基础(二):面向对象
  7. ubuntu16.04卸载火狐,Amazon
  8. HMM中的前向法(转)
  9. 第六章 第一个Linux驱动程序:统计单词个数
  10. jquery实现div自适应浏览器高度