JAVA processing Excel Files---Generate a simple Excel file __java

Source: Internet
Author: User

In the real office, we often have such a request: the report directly in Excel to open. There is such a demand in practice. Query the user for all information provided by the selected resource and generate Excel for download. But in the query we need to check the information provided by the user to see if there is a mistake (ID). There is error generating error information in Excel.

The Apache POI project is the more mature HSSF interface for working with Excel objects. In fact, poi not only works with Excel, it can also handle word, PowerPoint, Visio, and even outlook.

Here I'll first explain how to build Excel using POI.

First, before we build Excel, we need to understand the organization of Excel files. In poi, this is understood: An Excel file corresponds to a workbook, and a workerbook is composed of several sheet. A sheet has multiple row, and a row typically has multiple cell.

For the above four nouns we can understand in the following figure

Several basic objects are provided for the build Excel,poi:

Hssfworkbook the Document object for Excel

Hssfsheet Excel's Form

Hssfrow rows of Excel

Hssfcell Excel Grid Unit

From the pictures above and the organizational structure of Excel, we can understand the steps to create Excel.

1, generate Document Object Hsshworkbook.

2, through Hssfworkbook to generate form Hssfsheet.

3, through Hssfsheet to generate row Hssfrow

4, Generate cell Hssfcell by Hssfrow.

Here is the presentation code:

ID error Bean (errorcondition.java)

[Java]  View plain  copy  print? /**   * @Project: excel   * @Author: chenssy   * @Date: 2013-4-4   * @Copyright: chenssy all rights reserved.   */   public class  ErrorCondition {       private String name; //  Name        private String idCard; //  ID         private String status; //  Error status        private  String message; //  error message           errorcondition ( String name,string idcard,string status,string message) {            this.name = name;            this.idCard = idCard;       &NBsp;   this.status = status;            this.message = message;       }               public string getname ()  {            return name;       }           public void setname (string name)  {            this.name = name;       }           public string getidcard ()  {            return idCard;       }           public void setidcard (string idcard)  {            this.idcard = idcard;       }           public string getstatus ()  {            return status;       }     

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.