Skip to content

Allows easy conversion from pojo to excel sheets using annotations

License

Notifications You must be signed in to change notification settings

AbhijitSinha1/generic-excel-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generic Excel Reader/Writer

Usage

We start by first defining the Student and Teacher class, where the Student class is as follows:

public class Student implements IExcelObject {

	@GenericExcelColumn("Student Name")
	private String name;

	@GenericExcelColumn("Father's Name")
	private String fatherName;

	@GenericExcelColumn(value = "Student Age")
	private int age;

	@GenericExcelColumn("Student Height")
	private double height;

	@GenericExcelColumn("Student Weight")
	private double weight;

	@GenericExcelColumn("School")
	private String school;

	@GenericExcelColumn("Grade")
	private int grade;

	@GenericExcelColumn("section")
	private char section;

	// ------------------------------------------
	// getter and setter methods
}

Similarly Teacher class is:

public class Teacher implements IExcelObject {
	@GenericExcelColumn("Teacher Name")
	private String name;

	@GenericExcelColumn("School")
	private String school;

	@GenericExcelColumn("Grade")
	private int grade;

	@GenericExcelColumn("Section")
	private char section;

	@GenericExcelColumn("Subject")
	private String subject;

	// ------------------------------------------
	// getter and setter methods
}

Excel Write

Map<String, List<T>> map = new HashMap<>();
map.put("Students", fetchStudents());
map.put("Teachers", fetchTeachers());
GenericExcelHandler.write(map, "/path/to/excel/file.xls");

This will create an excel file with 2 sheets named Students and Teachers and populate the sheets with the corresponding data.

Excel Read

GenericExcelHandler geh = GenericExcelHandler.of("/path/to/excel/file.xls");
List<Student> students = geh.read("Students", Student.class);
List<Teacher> teachers = geh.read("Teachers", Teacher.class);

This will read the excel file which contains sheets named Students and Teachers and create a list of corresponding objects.

About

Allows easy conversion from pojo to excel sheets using annotations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages