Introduction
The report output is the content which the development database application often involves, but the general report often lacks the universality, does not facilitate the user to personalize edits. Excel is the WinDOS platform excellent spreadsheet software, if the report output into Excel format, users can use the powerful features of Excel to edit the report to meet their special needs. However, for a long time, Java programs cannot manipulate Excel directly because of their cross-platform characteristics. To achieve a pure Java Excel solution, Apache Jakara launched a free open source project poi. POI is now relatively mature and can handle Ms Excel (97-2002) objects. Some companies in the country have used POI in their Web projects such as office automation.
Download and installation of POI
Please go to the website Http://jakarta.apache.org/site/downloads/downloads_ poi.cgi Right-click the hyperlink 2.5.1.zip download compression Package Poi-bin-2.5.1-final-20040804.zip and extract the directory structure as shown in Figure 2.1. We mainly use Poi-2.5.1-final-20040804.jar this library file. Add the path to the Poi-2.5.1-final-20040804.jar file to the system environment variable classpath, or you will not be able to compile the following sample program.
Figure 2.1 POI directory structure
Preliminary use of POI
The objects that POI provides to users are in the Org.apache.poi.hssf.usermodel package, and the main parts include Excel objects, styles and formatting, and auxiliary operations.
The main objects are shown in Table 3.1:
Table 3.1 Poi main objects
Poi Object Name |
The corresponding Excel object |
Hssfworkbook |
Work book |
Hssfsheet |
Work table |
Hssfrow |
Yes |
Hssfcell |
Cell |
Let's look at the following example, using the object in table 3.1 to create an Excel file Test.xls in the current directory of the program, write the contents in the first cell, and then read the contents of the first cell.