public void excel(HttpServletResponse response, ProdFlowSearchVM search) throws IOException { setExcelDownloadResponse(response, "物料流转报表-" + DateTimeFormat.format(LocalDate.now(), "yyyy-MM-dd") + ".xlsx"); ReportData reportData = search(search); EasyExcel.write(response.getOutputStream()) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .head(reportData.getExcelHead()).sheet("物料流转报表") .doWrite(reportData.getExcelContent()); }
时间: 2024-04-06 14:34:18 浏览: 130
这段代码实现了一个excel导出功能,首先调用了setExcelDownloadResponse方法设置响应头,告诉浏览器要下载一个Excel文件,并设置下载文件名。然后调用search方法获取需要导出的数据,返回一个ReportData对象。接着使用EasyExcel库将数据写入Excel文件中,并设置了一个列宽自适应的样式策略。最后将写入的Excel文件内容通过response的输出流输出到浏览器端。
阅读全文
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)