FastExcel 本地开发和Linux上上传Resource文件的差异性

不能直接通过路径来获取

这个是一个下载导出文件的操作

java 复制代码
@GetMapping(value = "/export/all")
public void exportAll(HttpServletResponse response, LaylineListReq req) throws IOException {
    // 从类路径下获取 Excel 文件资源
    ClassPathResource classPathResource = new ClassPathResource("template/放线表主数据导入系统模板_template.xlsx");
    // 获取文件输入流
    InputStream inputStream = classPathResource.getInputStream();

    String fileName = "xxx"

    fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
    response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");

    EasyExcel.write(response.getOutputStream())
            .withTemplate(inputStream)
            .sheet()
            .doFill(list);
}

获取填充模版也需要先转换成 inputStream,不能照着官方的写法读取文件,下面是官方的写法,可以对比一下

相关推荐
水痕0134 分钟前
gin结合minio来做文件存储
java·eureka·gin
寒士obj43 分钟前
Spring事物
java·spring
柯南二号2 小时前
【Java后端】Spring Boot 集成 MyBatis-Plus 全攻略
java·spring boot·mybatis
桦说编程9 小时前
Java 中如何创建不可变类型
java·后端·函数式编程
lifallen9 小时前
Java Stream sort算子实现:SortedOps
java·开发语言
IT毕设实战小研9 小时前
基于Spring Boot 4s店车辆管理系统 租车管理系统 停车位管理系统 智慧车辆管理系统
java·开发语言·spring boot·后端·spring·毕业设计·课程设计
没有bug.的程序员10 小时前
JVM 总览与运行原理:深入Java虚拟机的核心引擎
java·jvm·python·虚拟机
甄超锋10 小时前
Java ArrayList的介绍及用法
java·windows·spring boot·python·spring·spring cloud·tomcat
阿华的代码王国11 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
Zyy~11 小时前
《设计模式》装饰模式
java·设计模式