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.