@PostMapping("/downloadTemplate")
@Operation(summary="下载入职excel模板")
public void downloadExcel(HttpServletResponse response){
try{
//获取输入流,原始模板位置
String filePath = "template/gridPersonTemplate.xlsx";
ClassPathResource resource = new ClassPathResource(filePath);
InputStream bis = resource.getInputStream();
//假如以中文名下载的话,设置下载文件名称
String filename = "gridPersonTemplate1.xlsx";
//转码,免得文件名中文乱码
filename = URLEncoder.encode(filename,"UTF-8");
//设置文件下载头
response.addHeader("Content-Disposition", "attachment;filename=" + filename);
//1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
response.setContentType("multipart/form-data");
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
int len = 0;
while((len = bis.read()) != -1){
out.write(len);
out.flush();
}
out.close();
}catch (Exception e){
log.error(e.getMessage());
}
5分钟下载excel模板
被程序耽误的胡先生2025-02-22 8:25
相关推荐
瀚高PG实验室8 小时前
数据库安全配置指导charlie1145141918 小时前
从零开始理解 CSS:让网页“活”起来的语言2new_daimond8 小时前
Linux 服务器内存监控与优化指南一介草民丶8 小时前
Linux | Mongodb 6 离线安装赖small强8 小时前
Linux 线程相关结构对照表与关系图Justin_198 小时前
部署zabbix浪裡遊8 小时前
Next.js路由系统mapbar_front8 小时前
职场中的顶级能力—服务意识Deamon Tree8 小时前
【设计题】如何实现限流器STUPID MAN8 小时前
Linux使用tomcat发布vue打包的dist或html