@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
相关推荐
小汐睡着了4 分钟前
解决虚拟机VMware与宿主机网络不通的问题-errorxdxghy09214 分钟前
mini centos7+k3s部署(镜像拉取解决版)老华带你飞5 分钟前
列车售票|基于springboot 列车售票系统(源码+数据库+文档)了一梨13 分钟前
外设与接口:按键输入 (libgpiod)幸运小圣15 分钟前
深入理解ref、reactive【Vue3工程级指南】用户479492835691516 分钟前
面试官最爱挖的坑:用户 Token 到底该存哪?java_logo17 分钟前
LinuxServer.io LibreOffice 容器化部署指南Irene199121 分钟前
Web前端开发中的垃圾回收详解Heo30 分钟前
Vue3.4中diff算法核心梳理惜.己32 分钟前
前端笔记(二)