2019-05-17 小试阿里巴巴EasyExcel导出Excel 添加easyexcel的maven依赖12345<dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>1.1.1</version> </dependency> 导出的模型需要继承BaseRowModel,然后可以在每个属性上设置所在的列和一些format12345678910111213141516171819202122232425262728293031323334public class GoodsOrderExportDto extends BaseRowModel { @ExcelProperty(value = "订单序号",index = 0) private Long orderId; @ExcelProperty(value = "订单编号",index = 1) private String orderCode; @ExcelProperty(value = "商品序号",index = 2) private Long goodsId; @ExcelProperty(value = "商品名称",index = 3) private String goodsTitle; @ExcelProperty(value = "商品链接",index = 4) private String goodsDetailsUrl; @ExcelProperty(value = "商品图片",index = 5) private String goodsPhoto; @ExcelProperty(value = "商品数量",index = 6) private Long goodsNum; @ExcelProperty(value = "商品价格",index = 7) private BigDecimal goodsAmt; @ExcelProperty(value = "区域公司",index = 8) private Long areaComp; @ExcelProperty(value = "付款时间",index = 12,format = "yy-MM-dd hh:mm:ss") private Date payTime;} 最后在控制器输出12345678910111213141516171819202122232425262728293031323334@RequestMapping(value = "export",method = RequestMethod.GET) public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { List<GoodsOrderDto> orderDtoList = goodsOrderServiceRemote.querGoodsOrderList(); List<GoodsOrderExportDto> orderExportDtoList = Collections.emptyList(); if (CollectionUtils.isNotEmpty(orderDtoList)){ orderExportDtoList = new ArrayList<>(orderDtoList.size()); for (GoodsOrderDto goodsOrderDto : orderDtoList) { GoodsOrderExportDto goodsOrderExportDto = new GoodsOrderExportDto(); BeanUtils.copyProperties(goodsOrderDto,goodsOrderExportDto); orderExportDtoList.add(goodsOrderExportDto); } orderDtoList.clear(); } // 设定输出文件头 response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("订单导出.xls", "UTF-8")); // 定义输出类型 response.setContentType("application/msexcel"); OutputStream outputStream = response.getOutputStream(); ExcelWriter excelWriter = new ExcelWriter(outputStream, ExcelTypeEnum.XLS); Sheet sheet = new Sheet(1, 0, GoodsOrderExportDto.class); excelWriter.write(orderExportDtoList,sheet); outputStream.flush(); excelWriter.finish(); outputStream.close(); } 作者: Sam 发布时间: 2019-05-17 23:43:39 最后更新: 2019-12-09 23:03:26 文章链接: https://ydstudios.gitee.io/post/76eb7bfd.html 版权声明: 本网所有文章除特别声明外, 禁止未经授权转载,违者依法追究相关法律责任! Newer >> Dubbo消费者consumer捕捉服务提供者provider抛出的自定义异常 Older << 查看依赖第三方jar最低要求运行的jdk版本 首页 归档 关于 友链