Poi excel is automatically converted to javabean and supports second-level conversion of reference type attributes.

Source: Internet
Author: User

Recently, you need to use the excel import function. When importing students, you need to specify the class to use excel to import data at one time!

Modifying previous Code supports conversion of reference classes in attributes.

The test object is a User object. The javabean structure is as follows:

Private String username;
Private int id;
Private String name;
Private Date birthday;
Private long height;
Private double salary;
Private User user;

Use the test code:

Map Header = new HashMap ();
Header. put ("no.", "id ");
Header. put ("username", "username ");
Header. put ("name", "name ");
Header. put ("birthday", "birthday ");
Header. put ("height", "height ");
Header. put ("salary", "salary ");
Header. put ("child", "user. username ");
Header. put ("child name", "user. name ");
Header. put ("birthday", "user. birthday ");
ExcelImport export = new ExcelImport (header );
// Export. init (new File ("src/user.xls "));
Export. init (new FileInputStream (new File ("src/user.xls ")));
List Users = export. bindToModels (User. class, true );
For (User u: users ){
System. out. println (u );
}

Conversion Result

Excel structure:

:

Http://download.csdn.net/detail/believer123/7317397



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.