java - 在 java 中导入 .xlsx 文件时出现 OutOfMemoryException

标签 java apache-poi xlsx

我尝试通过两种方式导入 .xlsx 文件:

1) 如果我从 eclipse 运行并且导入,我就能够成功导入

2) 如果我为我的产品制作一个 .jar 文件并作为独立应用程序运行而不使用 eclipse,我将收到 OutOfMemoryException,因此无法导入

我的文件大小约为 3mb,我使用了 poi 3.9、poi-ooxml-3.9、poi-ooxml-schemas-3.9、dom4j 和 xmlbeans 作为外部 jar。

我什至尝试过诸如 -Xmx1g、-Xms1024M -Xmx1024M 等参数。

请帮助我如何从我的独立应用程序导入 xlsx 文件。

最佳答案

也许你可以使用streaming API (SXSSF) .

Since 3.8-beta3, POI provides a low-memory footprint SXSSF API built on top of XSSF.

SXSSF is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.

关于java - 在 java 中导入 .xlsx 文件时出现 OutOfMemoryException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21547576/

相关文章:

java - 在android中未经身份验证的电子邮件

java - 在 Spring 中使用 JPA 规范获取要执行的查询

apache-poi - Apache poi : how to create chart with both bar and line?

api - 使用字节流和 Dropbox API 损坏 docx 文件

java - setBoldweight 不起作用

java - 消息传递代理和缓冲区

java - Eclipse 编译器和 javac 之间的差异 - 枚举、接口(interface)和泛型

java - ECMAScript 与 C/Java 的 ConditionalExpression 语法差异

javascript - 将 XLSX 导入到 JSON(不带工作表名称)

java - 从 INPUT-STREAM 加载大型 xlsx 文件,抛出 OutOfMemoryError Apache POI