当前位置: 首页 > article >正文

5分钟下载excel模板

@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());
    }

http://www.kler.cn/a/556312.html

相关文章:

  • 【deepseek】本地部署+RAG知识库挂载+对话测试
  • 【Film】论文:2024 视频生成可以取代摄影师吗?生成视频的电影语言研究
  • GB28181协议详解
  • RabbitMQ报错:Shutdown Signal channel error; protocol method
  • 浅谈Word2vec算法模型
  • SpringBoot+Vue+Mysql苍穹外卖
  • 设备树及gpio子系统及ioctl控制及字符设备驱动及内核模块编程事项仨LED灯说点就点说灭就灭
  • VMWare安装Debian操作系统
  • CSS 解决 Flex 布局中 justify-content: space-between; 导致最后一排项目分散对齐的问题
  • 数据结构——二叉树经典习题讲解
  • MATLAB学习之旅:从入门到基础实践
  • 【.NET全栈】.NET包含的所有技术
  • Github开源AI LLM大语言模型WebUI框架推荐
  • 【Gin】| 框架源码解析 :路由详解
  • QT SQL框架及QSqlDatabase类
  • MATLAB | 设置滑动窗口计算栅格数据的CV变异系数
  • 装win10系统提示“windows无法安装到这个磁盘,选中的磁盘采用GPT分区形式”解决方法
  • 计算机视觉算法实战——图像风格迁移(主页有源码)
  • solidity之Foundry安装配置(一)
  • 利用Postman和Apipost进行WebSocket调试和文档设计