@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
相关推荐
IT_陈寒40 分钟前
Python开发者必须掌握的12个高效数据处理技巧,用过都说香!gnip8 小时前
企业级配置式表单组件封装一只叫煤球的猫9 小时前
写代码很6,面试秒变菜鸟?不卖课,面试官视角走心探讨excel10 小时前
Three.js 材质(Material)详解 —— 区别、原理、场景与示例掘金安东尼10 小时前
抛弃自定义模态框:原生Dialog的实力皮皮林55111 小时前
IDEA 源码阅读利器,你居然还不会?hj5914_前端新手14 小时前
javascript基础- 函数中 this 指向、call、apply、bind薛定谔的算法14 小时前
低代码编辑器项目设计与实现:以JSON为核心的数据驱动架构Hilaku14 小时前
都2025年了,我们还有必要为了兼容性,去写那么多polyfill吗?yangcode14 小时前
iOS 苹果内购 Storekit 2