使用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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章