记 EasyExcel 使用的一次大坑,使用EasyExcel的错误。

一、前言

     EasyExcel 作为阿里的开源软件,(无数LOG)。最近在写文件下载的功能,需要将数据库中的数据进行Excel导出。官方写的文档很全了,我也不能直接搬人家的是吧。除了给出基本的方法,着重是 问题的解决,找了半天。

      你对着官网直接抄,如果不报错,那么你可以 ctrl + w。 如果报错则继续看吧。

    

二、入门

  2.1 添加maven依赖

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>easyexcel</artifactId>
    <version>2.0.5</version>
</dependency>

     版本号自己看着办。目前最新的是2.2.6。

2.2 service 输出文件

@Async   //下载文件,肯定多线程
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) //异常
public void downLoadTransFile(PayOrderFlowQueryAllReq req, HttpServletResponse response) throws Exception {
    response.setContentType("application/vnd.ms-excel");  // excel 的响应头
    response.setCharacterEncoding("utf-8");
    // 文件名字
    String fileName = URLEncoder.encode(System.currentTimeMillis() + "yourName", "UTF-8");   
    response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
    List<你的实体类> resp = 你的List集合的数据;
    EasyExcel.write(response.getOutputStream(), excel首行的column.class).sheet("模板").doWrite(resp);
}

2.3   excel首行的column.class

public class ddddd{

    @ExcelProperty(value = "你想写什么就写什么")
    private String a;

    @ExcelProperty(value = "excel 首行 ")
    private String b;

}

2.4 完了

三、报错 - 截取部分错误;省的密密麻麻的一堆没用的东西

错误:

错误1:Error   DOMSource cannot be processed: check that saxon8-dom.jar is on the classpath

错误2: com.alibaba.excel.exception.ExcelGenerateException: Can not close IO

错误3:Caused by: org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@3f93e206

错误4:Caused by: org.apache.poi.openxml4j.exceptions.OpenXML4JException: The part /docProps/core.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@3f93e206

 。  。   。  。

解决:

    网上搜了一堆:增加 easyExcel 的版本,增加 poi的版本 等等。可能有用,但是我折腾了半天,最后发现,需要添加3个依赖,如果你添加两个问题就可以解决的话,第三个就可以不用添加了。

    新增的依赖:

  

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>net.sf.saxon</groupId>
    <artifactId>saxon-dom</artifactId>
    <version>8.7</version>
    <scope>compile</scope>
</dependency>

  

  • 9
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值