I am reading excel file using jxl library.But I am facing a problem when i want add the cell content into pojo class property . such I have Employee class;
public class Employee {
private String id;
private String name;
private String email;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
public static void read(String path) throws IOException {
File inputWorkbook = new File(path);
Workbook w;
String[] excel_data = new String[3];
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
Vector<Employee> data = new Vector<Employee>();
for (int j = 1; j < sheet.getRows(); j++)
{
Employee emp = new Employee()
for (int i = 0; i < sheet.getColumns(); i++)
{
Cell cell = sheet.getCell(i, j);
// d.add(cell.getContents());
emp.setId(cell.getContents());
emp.setName(cell.getContents());
emp.setEmail(cell.getContents());
}
// d.add("\n");
data.add(emp);
//insertEmployee(emp);
}
here my code i can add cell content into vector object. but i want set cell content value into Employee class property.Please tell how I achieve this.I am not getting right value from emp object.What I was doing wrong in my code when i adding content into list
You will have to set the values manually.
You can write a switch statement and set the values for each column index like this: