@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
相关推荐
HTouying27 分钟前
线程池【工具类】深盾科技33 分钟前
融合C++与Python:兼顾开发效率与运行性能我待_JAVA_如初恋33 分钟前
idea创建MavenJavaWeb项目以后,包结构缺java来深圳40 分钟前
leetcode 739. 每日温度问道飞鱼43 分钟前
【Linux知识】Linux 虚拟机磁盘扩缩容操作指南(按文件系统分类)CC大煊43 分钟前
【java】Druid数据库连接池完整配置指南:从入门到生产环境优化羽沢311 小时前
ECharts 学习LYFlied1 小时前
WebAssembly (Wasm) 跨端方案深度解析七月丶1 小时前
实战复盘:我为什么把 TypeScript 写的 CLI 工具用 Rust 重写了一遍?