@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
相关推荐
buhuimaren_几秒前
GFS分布式文件系统踩着两条虫2 分钟前
VTJ:核心引擎程序员老邢4 分钟前
【技术底稿 18】FTP 文件处理 + LibreOffice Word 转 PDF 在线预览 + 集群乱码终极排查全记录被摘下的星星13 分钟前
网络设备有哪些aini_lovee15 分钟前
基于C#的三菱PLC串口通信实现方案不做无法实现的梦~15 分钟前
显示屏和显卡驱动问题完整解决教程---ubuntu22.04安装显卡驱动解决显示屏黑屏幕问题.柒宇.16 分钟前
共享文件服务NFS服务器:NFS实战详解磊 子22 分钟前
类模板与派生1GISer_Jing24 分钟前
AI时代前端开发者成长计划一叶之秋141225 分钟前
通信之道:解锁Linux进程间通信的无限可能(三)