java 下載excel模板


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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM