Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read excel file of 2MB and having around 200 sheets

 
Shaveta Sharma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a program to read excel file using POI. My file is of 2MB and has 200 sheets.
At run time I am getting below error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.Integer.valueOf(Unknown Source)
at org.apache.poi.hssf.usermodel.HSSFSheet.addRow(HSSFSheet.java:299)
at org.apache.poi.hssf.usermodel.HSSFSheet.createRowFromRecord(HSSFSheet.java:218)
at org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet(HSSFSheet.java:142)
at org.apache.poi.hssf.usermodel.HSSFSheet.<init>(HSSFSheet.java:117)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:288)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:201)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:183)
at ReadXMLTemplate.readSDDBTmpl(ReadXMLTemplate.java:117)

Please help..
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
The solution to your problem may be as simple as increasing the heap size. You do that with the -Xmx command line switch. see here

I see you are using POI. There is an event-based model that may be more memory efficient than the user model when working with large files. see here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic