java 下载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);
}

 

相关文章:

  • 2021-12-29
  • 2021-10-19
  • 2021-09-01
  • 2021-12-01
  • 2020-03-14
猜你喜欢
  • 2021-06-10
  • 2021-09-15
  • 2021-05-05
  • 2021-09-15
  • 2021-09-23
  • 2021-11-17
  • 2021-09-11
相关资源
相似解决方案