@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
相关推荐
Hashan6 分钟前
Elpis:抽离业务代码,发布NPM包quikai198111 分钟前
python练习第六组222you12 分钟前
线程的常用方法用户479492835691514 分钟前
0.1加0.2为什么不等于0.3-答不上来的都挂了rit843249915 分钟前
C#实现的远程控制系统Vect__21 分钟前
初识操作系统若风的雨22 分钟前
pcie bar 地址对齐规则诺斯贝克24 分钟前
Unable to create converter for xxx.NetworkResponse<Auth> for method AuthServicelisthi52024 分钟前
针对燃油运输和车辆调度问题的蚁群算法MATLAB实现LRX_19892725 分钟前
华为设备配置练习(七)VRRP 配置