数据库导出excel,前后端分离

时间:2023-03-08 17:52:01

主要参考了这篇博文:https://www.cnblogs.com/jerehedu/p/4343509.html  2.3和2.4

采用xssf,依赖:compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'

public void export(HttpServletResponse response) throws Exception {
XSSFWorkbook workbook = ...
response.setHeader("Content-Type", "application/octet-stream");
response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;");
workbook.write(response.getOutputStream());
response.flushBuffer();
} 要注意的是前端接受到的是一个response,需要从里面取出数据。 后续:远程图片也需要导出到excel,参考:
https://www.cnblogs.com/hwaggLee/p/5631287.html
https://blog.****.net/qq_24076135/article/details/78045034