/**
* 下载导入模板
*/
@RequestMapping(value = "/exportTemplate")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
try {
ClassPathResource classPathResource = new ClassPathResource("templates/renwu.xlsx");
InputStream inputStream = classPathResource.getInputStream();
//生成目标文件
File somethingFile = File.createTempFile("Topic_Template", ".xlsx");
try {
FileUtils.copyInputStreamToFile(inputStream, somethingFile);
} finally {
IOUtils.closeQuietly(inputStream);
}
InputStream in = new FileInputStream(somethingFile);
response.setHeader("Content-Disposition","attachment;filename=" + new String(("xxxx.xlsx").getBytes("gb2312"),"iso-8859-1"));
response.setContentType("application/octet-stream; charset=utf-8");
response.addHeader("Content-Length",in.available()+"");
ServletOutputStream out=response.getOutputStream();
IOUtils.copy(in, out);
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
下载模板 实例
最新推荐文章于 2024-03-26 17:12:28 发布