项目作者: sukhjindersukh

项目描述 :
This is excel slim library to read excel sheet as java class(pojo).
高级语言: Java
项目地址: git://github.com/sukhjindersukh/exclim.git
创建时间: 2019-06-18T09:00:26Z
项目社区:https://github.com/sukhjindersukh/exclim

开源协议:MIT License

下载


Welcome to exclim!

This is excel slim library to read excel sheet as Java POJO(Plain Old Java Object).

Add dependency for your project

  1. <dependency>
  2. <groupId>com.github.sukhjindersukh</groupId>
  3. <artifactId>Exlim</artifactId>
  4. <version>1.1</version>
  5. </dependency>

How to use it

  1. Create a Excel sheet let say Employee with fields
    Name and DOB.
Name DOB
Employee_1 25-05-1989
Employee_2 15-02-1980
Employee_3 02-05-2000

Now read all data in java

  1. Create a simple java class with exactly same name of your sheet in our case Employee

    1. public class Employee {
    2. String Name, DOB;
    3. public String getName() {
    4. return Name;
    5. }
    6. public void setName(String name) {
    7. Name = name;
    8. }
    9. public String getDOB() {
    10. return DOB;
    11. }
    12. public void setDOB(String DOB) {
    13. this.DOB = DOB;
    14. }
    15. @Override
    16. public String toString() {
    17. return "Employee{" +
    18. "Name='" + Name + '\'' +
    19. ", DOB='" + DOB + '\'' +
    20. '}';
    21. }
    22. }

    If you dont want to use getter setter you can use project lombok dependency to reduce your getter setter and toString code.

    1. <dependency>
    2. <groupId>org.projectlombok</groupId>
    3. <artifactId>lombok</artifactId>
    4. <version>1.18.8</version>
    5. <scope>provided</scope>
    6. </dependency>

    @Data thats it. You are ready to use" class="reference-link">Aftre addition of library write your java POJO(Plain Old Java Object) just use annotation @Data thats it. You are ready to use

    1. @Data
    2. public class Employee {
    3. String Name, DOB;
    4. }
  1. Create another java class with to test our Employee class is working or not
  1. public class EmployeeModelTest {
  2. @Test
  3. public void employeeTest(){
  4. Exl exl = new Exl();
  5. exl.setDateDataFormat("MM-dd-yyy");
  6. String path = "src/test/resources/TestData.xlsx";
  7. List<Employee> employees = exl.read(Employee.class, path);
  8. for (Employee employee : employees) {
  9. System.out.println(employee.toString());
  10. }
  11. Assert.assertTrue(employees.size()>0);
  12. }
  13. }

Default date time format is dd-MM-yyyy

One another way to use it

  1. Exl exl = new Exl();
  2. exl.openWorkbook(path);
  3. Recordset recordset =exl.getRecords("Employee");
  4. exl.closeWorkbook();
  5. List<Recordset.Record> records = recordset.getRecords();
  6. for(Recordset.Record record:records){
  7. System.out.println(record.getValue("Name"));
  8. }

Generate your jar!

mvn clean package

Thanks for coming here! Feedback highly appreciated.

If you like it then hit :sun_with_face: