现象:
在JAVA的resources文件夹中放置了execl模板,想要在读取模板的基础上编辑并下载,结果在转换为workbook时,报以下问题。
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Could not open the specified zip entry source stream
org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:205)
org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:187)
org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:161)
......
原因:
本来以为是路径的事情,后来才发现是放在resources中的文件,在maven进行编译的时候回被转码,导致文件内部混乱,无法读取。
解决:
maven编译命令中追加相关除外条件解决,详见以下的nonFilteredFileExtension配置:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-xmls</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>