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

猜你喜欢

转载自www.cnblogs.com/bt2882/p/13176665.html