java.io.IOException: ZIP entry size is too large or invalid
at org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.<init>(ZipArchiveFakeEntry.java:43)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:53)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:106)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:301)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:303)
查看错误堆栈,可以定位到 XSSFWorkbook hssfWorkbook = new XSSFWorkbook(inputStream)
对比了下工程src目录下与target目录下文件发现大小确实不一致:
在排查之后发现工程开启了 filtering,而filtering用于maven编译过程中做一些填充工作,因此需要在pom中增加一下配置:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<!--注意 exculde会将匹配到文件排除在编译以后的结果之外,因此下面会再有一个
filtering 的模块,再通过include的形式,将xlsx文件再如引入进来-->
<excludes>
<exclude>**/*.xlsx</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xlsx</include>
</includes>
</resource>
</resources>