通过IO流下载Excel文件

1、后台将文件通过输出流输出到前端

InputStream inputStream = this.getClass().getResourceAsStream("/template/XXX模板.xlsx");
Workbook workbook = new XSSFWorkbook(inputStream);
if (workbook!=null) {
    String fileName = "XXX模板.xlsx";
    String headStr = "attachment;fileName=\""+new String(fileName.getBytes("UTF-8"), "iso8859-1")+"\"";
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", headStr);
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
}

2、前端页面接收输出流,直接请求该接口即可,或者window.location.href= ' 接口 '

猜你喜欢

转载自www.cnblogs.com/a591378955/p/9342620.html