我尝试通过两种方式导入 .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/