Out of heap memory for XSSF java read excel file - java

Excel allows around 65K records in a .xls file.
For more data, I am using .xlsx file .
I used HSSF previously and now using XSSF for reading this xlsx in java.
Now my question is, when I save data in .xls (<65K ) and run with HSSF I am able to
and when storing it in .xlsx and reading with XSSF(<65K still) my program throws out of heap memory.
Want to know if it's even possible because I verified it multiple times.
What I also observed the same data as xls has file size 19MB and as xlsx as 16MB
still reading xls doesn't throw memory issue but xlsx does.
Any idea how to solve it
ans what might be the reason causing this behaviour.
I have tried changing multiple sizes from 1024M to 4096M
It either fails to create a VM with given size or throws out of heap space.
Why is it specifically for xlsx read and not when xls read.

Related

processing growing excel file with java spring

I want to process an excel file with java spring. I am using apche poi to process the file. The excel file is auto generated and keeps growing. Example: Excel file has 20 lines on day 1. On day 2 the excel file has 35 lines. The first 20 lines are the same, but there are 15 new lines. It is unknown how many lines are added or when the excel will be uploaded.
The data from the excel is mapped to POJOs and saved to the database.
Is there a fast and reliable way to identify which new lines were added and only proccess those lines?
edit: I realised that this might not be an excel processing problem but (also) a database optimisation problem.
You can use the newer API of Apache POI, SXSSF, which an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. It consumes less memory. Check this link.

POI workbookfactory read big Excel [duplicate]

This question already has answers here:
How to load a large xlsx file with Apache POI?
(8 answers)
Closed 2 years ago.
Is there a way to use WorkbookFactory with big Excel file? (5,5 MB)
Workbook wb = WorkbookFactory.create(new FileInputStream(file));
when the file became big, by using background-colors."
I get the error: java.io.IOException: GC overhead limit exceeded.
Altering the excel is not an option.
Is it possible to ignore the styles when reading the excel?
side info: The background was changed for a lot of rows that don't contain text.
Here is the answer to your question:
Writing
For writing very huge files, there is SXSSFWorkbook which allows to do a streaming write of data out to files (with certain limitations
on what you can do as only parts of the file are held in memory).
Reading
For reading very huge files, take a look at the sample XLSX2CSV which shows how you can read a file in streaming fashion (again with
some limitations on what information you can read out of the file, but
there are ways to get at most of it if necessary).

POI XSSF and SXSSF

I am writing an application to use JAVA POI to read over 65536 records from oracle table and write to EXCEL .XLSX via JAVA POI library XSSF and SXSSF.
However, the error "out of memory" pops up. We have tried the following ways but the problem still occurs.
Load 66000 records into memory and write to .XLSX file
a. Larger heap size “Java.exe –Xmx4096m –Xmx4096m –XX:MaxPermSize=256m” is applied
Result : It takes about an hour to run and the file cannot be created.
Process 66000 records by region
a. load each region records’ of a season from oracle table into memory
b. append each region records from memory to a single .XLSX file
c. Larger heap size Java.exe –Xmx4096m –Xmx4096m –XX:MaxPermSize=256m is applied
Result : When it processes about 30000 records, the java memory error still pops up.
Except rewriting the program by using XML, is there any chance of fixing the memory error issue of JAVA POI XSSF and SXSSF ?
Please kindly advise

Memory issues during conversion of large volume of XLSX file to CSV with POI

This is a very challenging task to me as i am doing pretty much R&D to get rid of OutOfMemroyError during conversion of XLSX to CSV and my excel file can have three sheets and each sheet with 60000 rows.
I used XSSF and SAX (Event API) recently since this approach consumes very less memory. However the Event API is triggering events only for things actually stored within the file and this can be cause for me.
Earlier to this Event API approach, i used Workbook class to process XLSX file and eventually i am getting out of memory during this workbook creation provided below.
Workbook workbook = WorkbookFactory.create(new File("myfile.xlsx"));
so, what is the best way to process large volume of XLSX data with apache POI?
Here is an example for reading a large xls file using sax parser. Sax parser will help you avoid OOM exceptions.
Error While Reading Large Excel Files (xlsx) Via Apache POI

POI heap space exception or any alternative java api for Excel 2007?

i've been searching around for a solution for this problem and haven't found anything good =(
so the problem is i need to create an excel file up to 50.000 registers and when i do this show me this error at 50.000 app register:
java heap space
as far as i'm looking on, one way to solve this is increasing the heap memory, but quite don't like me (first aids) because the problem persist if the file gets to bigger and the server freezes and comsume a lot of memory trying to do this and gets slow
i think a solution would be writte out the excel file instead of leaving the data in the heap memory, but i don't get it work
any ideas ?? or another framework for excel 2007 files ???????
Call the write() method on your HSSFWorkbook to persist your Excel workbook to a file:
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
But as this thread indicates there's no way to do streaming writes to file in POI. Alternatives to POI are jXLS (open source) or Aspose.Cells for Java (proprietary)

Categories

Resources