@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
相关推荐
深紫色的三北六号3 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)雨中飘荡的记忆5 小时前
ElasticJob分布式调度从入门到实战掘金安东尼6 小时前
让 JavaScript 更容易「善后」的新能力掘金安东尼6 小时前
用 HTMX 为 React Data Grid 加速实时更新SudosuBash7 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)灵感__idea8 小时前
Hello 算法:众里寻她千“百度”yinuo8 小时前
轻松接入大语言模型API -04袋鼠云数栈UED团队9 小时前
基于 Lexical 实现变量输入编辑器cipher9 小时前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"UrbanJazzerati9 小时前
非常友好的Vue 3 生命周期详解