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

相关推荐
YA33322 分钟前
java设计模式二、工厂
java·开发语言·设计模式
金色天际线-29 分钟前
Nginx 优化与防盗链配置指南
java·后端·spring
我爱挣钱我也要早睡!1 小时前
Java 复习笔记
java·开发语言·笔记
AD钙奶-lalala3 小时前
Mac OS上搭建 http server
java
皮皮林5517 小时前
SpringBoot 全局/局部双模式 Gzip 压缩实战:14MB GeoJSON 秒变 3MB
java·spring boot
weixin_456904277 小时前
Spring Boot 用户管理系统
java·spring boot·后端
趁你还年轻_7 小时前
异步编程CompletionService
java
DKPT8 小时前
Java内存区域与内存溢出
java·开发语言·jvm·笔记·学习
sibylyue8 小时前
Guava中常用的工具类
java·guava
奔跑吧邓邓子8 小时前
【Java实战㉞】从0到1:Spring Boot Web开发与接口设计实战
java·spring boot·实战·web开发·接口设计