0

I am trying to import an .xlsx file in 2 ways:

1) If I run from eclipse and if I import, I am able to import successfully

2) If I make a .jar file of my product and run as a stand alone application without using eclipse, I am getting an OutOfMemoryException and hence fails to import

My file size is around 3mb and I have used poi 3.9, poi-ooxml-3.9, poi-ooxml-schemas-3.9, dom4j and xmlbeans as external jars.

I have even tried arguments such as -Xmx1g, -Xms1024M -Xmx1024M etc..

Please help me how can I import an xlsx file even from my stand alone application.

5
  • How did you add the memory parameters using your jar? Commented Feb 4, 2014 at 8:43
  • xmx1024 (1GB max heap size that is) might not be sufficient, did you try to increase it further? Commented Feb 4, 2014 at 8:44
  • 1
    And you are sure Eclipse is using the same Java-VM as you do when running the application stand-alone? Commented Feb 4, 2014 at 8:46
  • Eclipse is sometimes bad try to restart Eclipse sometimes it solves this error Commented Feb 4, 2014 at 8:47
  • which workbook are you using? the sxssfworkbook uses streaming and should be preferred when a huge file is being imported or the heap space is limited. see poi.apache.org/spreadsheet/how-to.html#sxssf Commented Feb 4, 2014 at 8:53

1 Answer 1

4

Maybe you could use the 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.

Sign up to request clarification or add additional context in comments.

3 Comments

But i should be able to read both xls and xlsx files simultaneously.
@user3152686 With xls files, there's nothing that can be done to reduce memory usage, it will be loaded completely in memory, unlike with .xlsx files where you have a lot more options to control the memory used.
for xls you are instead out of luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.