How to convert my xlsx sheet to java object using Apache POI

前端 未结 9 1463
情书的邮戳
情书的邮戳 2020-12-14 22:06

can any one suggest me to convert my xlsx sheet to java object using Apache POI.

eq, my excel sheet contains two columns

  • emp_no emp_name
  • 01
9条回答
  •  长情又很酷
    2020-12-14 22:30

    Check the below repo. It was developed by keeping "ease of use" in head. https://github.com/millij/poi-object-mapper

    Initial version has been published to Maven Central.

    
        io.github.millij
        poi-object-mapper
        1.0.0
    
    

    Works similar to Jackson. Annotate your bean like below..

    @Sheet
    public class Employee {
        // Pick either field or its accessor methods to apply the Column mapping.
        ...
        @SheetColumn("Age")
        private Integer age;
        ...
        @SheetColumn("Name")
        public String getName() {
            return name;
        }
        ...
    }
    

    And to read..

    ...
    final File xlsxFile = new File("");
    final XlsReader reader = new XlsReader();
    List employees = reader.read(Employee.class, xlsxFile);
    ...
    

    As it stands, all primitive data types are supported. Still working on adding support for Date, Formula etc..

    Hope this helps.

提交回复
热议问题