jxls--按模板导出
来源:互联网 发布:淘宝耐克鞋正品 编辑:程序博客网 时间:2024/06/05 00:13
public void exportExcelOrder(HttpServletResponse response, String orderCode, String mobile) {ExportOrderDTO dto = service.findExportOrderDTOByOrderCode(orderCode, mobile);// 获取参数if (Objects.nonNull(dto)) {Map<String, ExportOrderDTO> beans = Maps.newHashMap();beans.put("entity", dto);XLSTransformer transformer = new XLSTransformer();InputStream in = null;OutputStream out = null;SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");String outputFileName = "OrderDetail_" + sdf.format(new Date()) + ".xlsx";response.setHeader("Content-Disposition", "attachment;filename=" + outputFileName);response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");try {URL url = ExportController.class.getResource("/static/file/" + "order_template.xlsx");// 判断是否为解决方案订单if(Objects.equals(dto.getOrderType(), OrderType.SOLUATE)){url = ExportController.class.getResource("/static/file/" + "solute_order_template.xlsx");}File file = new File(url.getFile());in = new BufferedInputStream(new FileInputStream(file));Workbook workbook = transformer.transformXLS(in, beans);if(Objects.equals(dto.getOrderType(), OrderType.SOLUATE)){// 合并单元格Sheet sheetAt = workbook.getSheetAt(0);int lastRowNum = sheetAt.getLastRowNum();sheetAt.addMergedRegion(new CellRangeAddress(lastRowNum-2, lastRowNum-2, 1, 3));sheetAt.addMergedRegion(new CellRangeAddress(lastRowNum-2, lastRowNum-2, 5, 7));sheetAt.addMergedRegion(new CellRangeAddress(lastRowNum, lastRowNum, 5, 7));}out = response.getOutputStream();workbook.write(out);out.flush();} catch (InvalidFormatException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}if (out != null) {try {out.close();} catch (IOException e) {e.printStackTrace();}}}}}
模板样例:
entity中的参数要与模板中的参数对应.
不知道什么原因,用第一个模板时,并不能完全按照模板导出,需要自己在controller中处理一下,猜测是因为foreach的原因.
阅读全文
0 0
- jxls--按模板导出
- 使用jxls按模板导出excel数据
- jxls模板导出excel
- jxls模板导出excel
- Excel 模板导出---JXLS
- JXLS模板导出EXCEL
- jxls 使用模板文件导出生成excel
- 利用JXLS根据模板导出Excel实例教程
- 利用JXLS根据模板导出Excel实例教程
- jxls读取模板导出Excel学习笔记
- JXLS模板导出excel--简单版
- JXLS模板导出excel--项目版
- jxls使用模板导出Excel表格
- JXLS-----JXLS导出Excel
- JXLS-----JXLS导出Excel实例
- java操作excel之jxls导出excel模板数据
- 利用JXLS根据模板填充数据导出Excel实例
- POI导出Excel模板工具类(使用jxls)
- MaxCompute 2.0:阿里巴巴的大数据进化之路
- 登录注册模块设计构思
- 虚拟机tomcat配置,使shiro项目对于SSL支持
- 通过reducer联合产生宽表
- java多线程学习——(1)认识Thread和Runnable
- jxls--按模板导出
- OTT系统和视频聚合软件初探
- shell编程报错:“syntax error near unexpected token `”
- python之scikit-learn的应用
- 秘密信息
- 联网判断
- 数组的操作方法
- iOS 关于UIAlertController、UIAlertView弹窗问题
- Java 时间相关 获取某月的某一天