@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
相关推荐
Wang's Blog29 分钟前
Java 接入Redis: 五大数据类型与存储结构选型Wang's Blog33 分钟前
Java 接入Redis: 字符串与哈希类型操作命令是店小二呀2 小时前
鸿蒙PC_Dart-Sass-ohos适配全记录2601_958352903 小时前
A-59U 仅 37mm 却集成 USB + 双波束?智慧物业老杨5 小时前
物业数字化落地思考:真正的转型,是底层数据秩序的重构星空7 小时前
金蝶苍穹build.gradle配置充电zcx8 小时前
Linux:4:开发工具详解泯泷8 小时前
那段文字是谁删的?Yjs 14 正式版之前,一套删除归属方案的实现与边界步行cgn10 小时前
Spring 基于 XML 的自动装配:byName 详解野槐11 小时前
前端项目优化(有了我,会发生...)