On the application of Excel report in Java program

Source: Internet
Author: User
Tags final zip

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.