aspose file tools*
The moose likes I/O and Streams and the fly likes OutOfMemoryError on reading big excel file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "OutOfMemoryError on reading big excel file" Watch "OutOfMemoryError on reading big excel file" New topic
Author

OutOfMemoryError on reading big excel file

Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 11
I am getting an OutOfMemoryError while trying to read a excel file(.xlsm) of size ~2Mb.
I am running this application on a websphere server. Is there any way i could read this file with out changing any server configurations?

Have tried to use this approach, but the red line gave me OutOfMemoryError.

OPCPackage pkg = OPCPackage.open(new File("sample.xlsm"));
XSSFWorkbook wb_template;
wb_template = new XSSFWorkbook(
pkg
);

SXSSFWorkbook wb = new SXSSFWorkbook(wb_template);
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Is increasing server heap space an option? If yes, try it!


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 11
I can do it for local deployment(in my machine), but dont have control over the server to which it will be deployed after development.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
From the documentation I gather that SXSSF is meant more for creating documents, not reading them: http://poi.apache.org/spreadsheet/how-to.html#sxssf

A low-memory approach to reading would be the XSSF event API: http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api

2 MB doesn't sound all that much, though. What are the JVM memory settings of the server?


Ping & DNS - updated with new look and Ping home screen widget
Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 11
Not sure about the current heap size. It will be the default of websphere 7.
Even increasing the heap size as given below dint helped me.
Initial heap size = 256 MB
Maximum heap size = 2048 MB


Planning to go with http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api
Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 11
What is relId of a sheet?
I couldn't understand from apache doc.
I tried with both sheetName & Sheet number. Both dint worked out.

--apache doc
public java.io.InputStream getSheet(java.lang.String relId)
throws java.io.IOException,
InvalidFormatException
Returns an InputStream to read the contents of the specified Sheet.
Parameters:
relId - The relationId of the sheet, from a r:id on the workbook
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
Not sure. Maybe open the file manually (xlsx files are just zip files containing various XML documents) and see if somewhere in there you find a sheet attribute that looks like "r:id". (And, of course, see what that value is in various spreadsheets so as to figure out the logic behind it.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutOfMemoryError on reading big excel file
 
Similar Threads
Reading a .xlsx excel file using XSSF
How to edit a large .xlsx(3 MB) file using apache poi ?
OutOfMemoryError in processing large xlsx file (167 MB) using Apache POI
Out of Memory Error - Java Heap Space while writing to Excel
Read a .xls,.xlsx file format using XSSF