接口传参数
(HttpServletRequest request,HttpServletResponse response)
调用easyExcel生成文件流导出
String fileName =name+"aaa.xlsx";
//调用业务,构造模板列表数据
//写入数据
OutputStream out = response.getOutputStream();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
//使用的easyexcel工具就这一行
EasyExcel.write(out, ExcelExportDTO.class).autoCloseStream(true).sheet("信息列表").doWrite(detectAlerts);
前端代码
downLoadXls(data, filename) {
var blob = new Blob([data], { type: 'application/vnd.ms-excel;charset=utf-8' });
let a = document.createElement('a');
let url = window.URL.createObjectURL(blob);
a.href = url
a.download = filename
a.click()
window.URL.revokeObjectURL(url)
},