EasyExcel工具使用时报错:org/apache/poi/ss/usermodel/Date1904Support找不到

一、问题描述

1.报错翻译为 找不到这个Date1904Suppor这个类

        耗尽了我4的时间各种方法都试过了,最终还是没有从根源上找到这个问题的原因,目前只是怀疑导入的依赖本身有BUG;我工具类中,下载的方法是如下写的。

public <T> Boolean download(HttpServletResponse response, String name, List<T> data, Class<T> head, String sheet) throws IOException {
        String codeType = "UTF8";
        try {
            // 告诉浏览器用什么软件可以打开此文件
            response.setHeader("content-Type", "application/vnd.ms-excel");
            // 下载文件的默认名称
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name + ".xlsx", codeType));
        } catch (UnsupportedEncodingException e) {
            log.error("设置响应头失败:", e);
            return false;
        }

        try {
            OutputStream outputStream = response.getOutputStream();
            EasyExcelFactory.write(outputStream, head)
                    .registerWriteHandler(new SimpleColumnWidthStyleStrategy(30))
                    .registerWriteHandler(new SimpleRowHeightStyleStrategy((short) 16, (short) 16))
                    .registerWriteHandler(setStyle())
                    .registerConverter(new LocalDateTimeStringConverter())
                    .sheet(sheet)
                    .doWrite(data);
       } catch (Exception e) {
            log.error("Excel文件下载", e);
            return false;
        }
        return true;
    }

 

        只要用postman发送请求,就报异常,excel文件可以下载,但是提示Excel文件格式损坏,并且只能更改扩展名为“xls”才能打开,打开之后无数据,并且为空文件。

二、问题解决

我这里没有对问题进行复现,觉得麻烦了。

这是我最开始直接引入的依赖

 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel-core</artifactId>
            <version>3.2.1</version>
<dependency>

本质上这个Eazyexcel还是引的poi的依赖,换了poi的版本,目前没报错了,之前一直报找不到一个类,所以还是换了poi的依赖版本

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel-core</artifactId>
            <version>3.2.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml-schemas</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.2</version>
        </dependency>

最后终于不报异常了,可以正常导入excel。

 

 文件可以正常打开了,有excel工具类相关的问题,可以留言交流。希望能帮助到大家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值