POI - ZIP条目大小太大

时间:2014-09-07 14:53:53

标签: java excel maven apache-poi jxls

我使用JXLS创建我的woorkbook。 JXLS使用下面的POI。要创建工作簿,JXLS需要文件或输入流。

使用文件对象,我得到了我想要的woorkbook。但是,对于流我得到错误 ZIP条目大小太大

JXLS lib使用

  

WorkbookFactory.create()

创建工作簿的方法。所以,我尝试使用ZipStream和PushbackStream;没有帮助。 我能够从我的Junit运行相同的代码。

我看了下面的帖子。 Why am I getting exception "IOException: ZIP entry size is too large" when trying to open an Excel file using Apache POI?

帖子的解决方案是Maven的变化。但是,这篇文章没有提到Maven所做的改变。

你有什么建议吗?

2 个答案:

答案 0 :(得分:7)

我发现了这个问题。问题是Maven忽略了我在资源中保存的文件。所以我添加了如下所示的资源过滤以包含我的Excel模板。

<resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>**/*.xlsx</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/*.xlsx</include>
            </includes>
        </resource>
</resources>

答案 1 :(得分:0)

对于我的项目,我添加了这些,所以 excel 和 word 文档不会被压缩

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