I have a large .xlsx excel sheet with 400,000 rows. I want to read and write in this existing workbook.
When i tried to read it in java with Apache poi, with following code:
FileInputStream fileInputStream = new FileInputStream(new File(excelPath));
Workbook wb = new XSSFWorkbook(fileInputStream);
Second line of this code takes RAM upto 5gb.
Apache POI has given a SXSSF Streaming API to handle large Excel file.
http://poi.apache.org/components/spreadsheet/how-to.html#sxssf
Now, when I instantiate SXSSF workbook with constructor without any parameter, it creates new Workbook and does not persist existing data of workbook. And other constructor of SXSSF workbook takes instance of XSSF workbook. And the problem starts arise here. When i made instance of XSSF workbook for my excel file, RAM goes high and OUTOFMEMORY exception thrown.
Is there any way to do read and write opration on existing Large excel workbook with more then 400,000 rows.
SXSSF
is for writing only. No reading/editing at all allowed. At most you can instantiate anSXSSFWorkbook
and append data, but not edit existing data. I have an application which reads and edits excel files which are up to 14MB in size. Though I need to add these command line parameters-Xms4g -Xmx12g
for it to work at all. Apache poi uses very much RAM to read files – XtremeBaumernew XSSFWorkbook(new File("file_path"))
ornew XSSFWorkbook(new FileInputStream(new File(excelPath)))
– XtremeBaumer