Programmatically Manipulating Microsoft Excel Spreadsheets with the Apache POI API
The Apache Jakarta POI project consists of Java APIs dedicated to the manipulation of files based on Microsoftís OLE 2 Compound Document format. In this article, youíll learn how to use the APIs of the POI project to read from and write to Microsoft Excel spreadsheets. As you will see, the programmatic liberty to manipulate Excel files represents a powerful offering to the Java programmer.
Programmatically Manipulating Microsoft Excel Spreadsheets with the Apache POI API - Letís Learn How to Read From a Spreadsheet (Page 3 of 4 )
While the Apache POI allows us to write to spreadsheets, it also allows us to read from them. In the code shown in Listing 2, we do just that, reading off the values of our states and their corresponding sales figures and directing them to the system console. Youíll notice how much of our code is similar to that of Listing 1. We again open our spreadsheet, which we specify is located at c:articlessales.xls. HSSFCell and HSSFRow objects are used to narrow and house the cells we want to read data from. We then use the getStringCellValue and getNumericCellValue methods to extract the cell data and display it to the console.