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,不能照着官方的写法读取文件,下面是官方的写法,可以对比一下

相关推荐
鲸沉梦落19 小时前
Java中的Stream
java
yihuiComeOn20 小时前
[源码系列:手写Spring] AOP第二节:JDK动态代理 - 当AOP遇见动态代理的浪漫邂逅
java·后端·spring
Porunarufu20 小时前
Java·关于List
java·开发语言
靠沿21 小时前
Java数据结构初阶——Collection、List的介绍与ArrayList
java·数据结构·list
程序猿小蒜21 小时前
基于springboot的的学生干部管理系统开发与设计
java·前端·spring boot·后端·spring
q***563821 小时前
Spring容器初始化扩展点:ApplicationContextInitializer
java·后端·spring
q***518921 小时前
SpringCloud系列教程:微服务的未来(十四)网关登录校验、自定义过滤器GlobalFilter、GatawayFilter
java·spring cloud·微服务
go__Ahead21 小时前
【Java】线程池源码解析
java·juc
wyhwust1 天前
数组----插入一个数到有序数列中
java·数据结构·算法
专注于大数据技术栈1 天前
java学习--final
java·开发语言·学习