Microsoft Excel and Java
by
, June 24th, 2011 at 12:38 AM (5126 Views)
For those who are looking for a Java library which can read/write to Microsoft's spreadsheet formats (.xls, and the newer .xlsx), I recently stumbled upon a library called the Apache POI Project. It's not particularly a new project, but it is still under active development and maintained. As an added bonus, Apache POI also supports word documents, power point presentations, and other document formats.
To me, one of the main benefits of Apache POI is the support for Microsoft Office 2007 document formats (JExcel doesn't have this, which is somewhat disappointing).
The Apache POI website also has very good "getting started" guides, as well as a logically ordered API structure.
Rather than write a redundant tutorial, I think I'll just post a link to the quick guide from the developers.
For Microsoft .xls (2003) and .xlsx (2007):
Busy Developers' Guide to HSSF+XSSF
For more in-depth tutorials or "How-To's":
The New Halloween Document
(ignore the strange names, the links are correct)
And as always, you can navigate around the Apache POI website if you want to learn more about using the Apache POI API.
Note: HSSF is the API to use when dealing with older spreadsheet formats (.xls), and XSSF is the API to use when dealing with the new spreadsheet format (.xlsx). As a general tip, you can replace instances of HSSF with XSSF and your code will work. For example:
HSSFWorkbook oldExcel = new HSSFWorkbook(); // the old .xls format XSSFWorkbook newExcel = new XSSFWorkbook(); // the new .xlsx format
I would not rely completely on this assumption, however. Check the Javadoc to make sure that the two API's do indeed line up.