使用jxls导出excel报错:Your InputStream was neither an OLE2 stream, nor an OOXML stream

最近使用接到导出excel报表的需求,本来想用poi的,听说jxls更简单快捷,便想试试。一开始demo写的都挺顺利的,把excel模板放到项目的resources下面后,出事了,一直报错:

         java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream

在网上找了好久,终于解决。

      原因: maven打包插件打包时,修改了excel模板文件,导致excel模板文件损坏,无法打开。

      解决方法:maven打包时不修改excel文件,pom.xml中打包插件配置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
            <nonFilteredFileExtension>xls</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

猜你喜欢

转载自blog.csdn.net/mlsama/article/details/89709966