@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 小时前
纯 CSS 实现弹性文字效果牛奶4 小时前
Vue 基础理论 & API 使用牛奶4 小时前
Vue 底层原理 & 新特性anOnion4 小时前
构建无障碍组件之Radio group patternpe7er4 小时前
状态提升:前端开发中的状态管理的设计思想SoaringHeart5 小时前
Flutter调试组件:打印任意组件尺寸位置信息 NRenderBox晚风予星6 小时前
Ant Design Token Lens 迎来了全面升级!支持在 .tsx 或 .ts 文件中直接使用 Design Tokensunny_6 小时前
⚡️ vite-plugin-oxc:从 Babel 到 Oxc,我为 Vite 写了一个高性能编译插件GIS之路6 小时前
ArcPy 开发环境搭建林小帅8 小时前
【笔记】OpenClaw 架构浅析