Java-Principle of object-oriented reading Excel Data

Source: Internet
Author: User

Reading Excel Data in Java is a frequent issue. Generally, developers use the jxl (Java Excel API) open-source framework to easily read Excel Data Files. However, it is not that simple in practical applications.

If you have the following requirements on Excel, the process becomes complicated:

1. Read the specified Excel form name

2. If there is a title, check whether the title meets the requirements (the title is not always in the first line)

3. Specify that some Columns cannot be null, repeated, conform to a regular expression, or be within the enumerated range.

.......

When the above problems are encountered, Java code can also be easily implemented. However, when these requirements are repeated, programming becomes cumbersome without technical content.

Some people think that they can abstract these common problems and write a common class to solve them. Yes, this can solve the above problem. However, to read an Excel file, you still need to program it.

In fact, we can solve all the above problems through configuration.

Implementation principle:

An Excel form is equivalent to a small database. Since hibernate implements an object-oriented database, we can also perform object-oriented operations on Excel files.

A form structure in an Excel table is generally the same as a bean object. The structure of the Excel table is associated with the attributes of the bean object through xml configuration, so that each row of data can initialize a bean object.

We can further encapsulate jxl and use the object-oriented principle to read Excel files!

Implementation Method:

(1) Use a ing file to configure the verification information and ing information (such as the hibernate ing file in hibernate ).

(3) read data in Excel Based on the ing file.




 


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.