1.我們把需要下載的的excel 模板放在resource下面,模板要什么樣子自己修改excel就好

1.接下來我們讀取需要下載的excel模板就好
String fileName="test";
ClassPathResource classPathResource = new ClassPathResource("template/eventAndProperty.xlsx");
// 判斷下載哪個excel
// 初始化流
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = classPathResource.getInputStream();
response.setContentType("application/x-msdownload");
outputStream = response.getOutputStream();
response.addHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes(),"iso-8859-1"));
// 執行流操作
IoUtils.copy(inputStream,outputStream);
} catch (IOException e) {
log.error(e.getMessage());
}finally {
// 關流
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
}