Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory-efficient Java library to read Excel files?

Is there a memory-efficient Java library to read large Microsoft Excel files (both .xls and .xlsx)? I have very limited experience with Apache POI, and it seemed to be a huge memory hog from what I recall (though perhaps this was just for writing and not for reading). Is there something better? Or am I misremembering and/or misusing POI?

It would be important for it to have a "friendly" open-source license as well.

like image 404
Michael McGowan Avatar asked Jan 20 '11 20:01

Michael McGowan


People also ask

Can Java read Excel files?

In Java, reading excel files is not similar to reading word files because of cells in excel files. JDK does not provide a direct API to read or write Microsoft Excel or Word documents. We have to rely on the third-party library that is Apache POI.

What are the jars required to read Excel file in Java?

You need poi-3.12. jar to read XLS file and poi-ooxml-3.12. jar to read XLSX file in Java.


2 Answers

Apache's POI library has an event-based API that has a smaller memory-footprint. Unfortunately, it only works with HSSF (Horrible Spreadsheet Format) and not XSSF (XML Spreadsheet Format - for OOXML files).

like image 181
Vivin Paliath Avatar answered Nov 03 '22 08:11

Vivin Paliath


The Excel file formats are (both) huge and extremely complicated, and anything that reads all of their possible contents is going to be equally huge and complicated. Remember they can contain ranges, macros, links, embedded stuff etc.

However if you are reading something simple like a grid of numbers, I recommend first converting the spreadsheet to something simpler like CSV and then reading that format.

like image 36
DJClayworth Avatar answered Nov 03 '22 08:11

DJClayworth