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"));
wb_template = new XSSFWorkbook(
); SXSSFWorkbook wb = new SXSSFWorkbook(wb_template);
What is relId of a sheet?
I couldn't understand from apache doc.
I tried with both sheetName & Sheet number. Both dint worked out.
public java.io.InputStream getSheet(java.lang.String relId)
Returns an InputStream to read the contents of the specified Sheet.
relId - The relationId of the sheet, from a r:id on the workbook
Joined: Mar 22, 2005
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.)
Sorry for the very very late update on this thread, but better late than never.
I have resolved this issue. Hope if i share it, it will be helpful for some one else.
Thanks Ulf Dittmer, followign reply helped me to resolve it
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"
Rename the .xlsx file as .zip. It will give you a zip file. Open it and you will see a folder called "xl". Inside "xl" folder concentrate on the following things.
worksheets folder : contains the xml representation of each sheet.
sharedStrings.xml : Common place for storing all the string values across sheets.
styles.xml : common place for holding the styles(color, formula...) applied to cells.
workbook.xml : Contains the information about all sheets in the .xlsx file
Now start the journey from workbook.xm. Inside this file all sheets are covered in <sheets> tag.
sheets are represented as <sheet> Eg: <sheet name="General" sheetId="15" r:id="rId1"/>
Take r:id, that will help you to access the General.xml which represents the General sheet of .xlsx file.
SharedStringsTable sharedStringsTable = reader.getSharedStringsTable(); // using this we can access sharedStrings.xml
StylesTable stylesTable = reader.getStylesTable(); // using this we can access styles.xml
Since we are streaming the XML, we dont have to worry about memory consumption.
Joined: Mar 22, 2005
Thanks for reporting back how the issue was solved; that should help others.