Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed

helloworld922

Microsoft Excel and Java

Rate this Entry
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.

Updated June 24th, 2011 at 01:40 AM by helloworld922

Categories
Uncategorized

Comments