一、问题描述

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

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

public Boolean download(HttpServletResponse response, String name, List data, Class 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”才能打开,打开之后无数据,并且为空文件。

二、问题解决

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

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

com.alibaba

easyexcel-core

3.2.1

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

com.alibaba

easyexcel-core

3.2.1

org.apache.poi

poi-ooxml

org.apache.poi

poi

org.apache.poi

poi-ooxml-schemas

org.apache.poi

poi-ooxml

5.2.3

org.apache.poi

poi

5.2.3

org.apache.poi

poi-ooxml-schemas

4.1.2

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

 

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

精彩文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: