0
votes

I'm trying to do the following, but am struggling with what would be the best approach, can anyone point me in the right direction?

I have a Java program with one simple POJO (let's say 5 properties), representing a Person, with which I want to convert exports from multiple source systems into, to store in my own database table.

public class Person

String salutation;
String first_name;
String last_name;
String email;

These sources can export their data with extra information that is not needed by the POJO (i.e. more than the 4 properties I have defined). So the XLS could look like this...

firstname     secondname     address1     address2     fax     phone     email 
John          Smith          My Street                 873637  2323829   [email protected]

My thought was to use POI (XSSFWorkbook) and find the Strings in the Header rows (firstname etc) - then, using an XML file that specifies the mapping (firstname = first_name), store the column index where I find the POJO property in a Map (with the column heaer), then loop through each row creating an object based on the mapping of property/header name/column index and the POJO properties.

Can anyone suggest if this is on the correct path?

1
This sounds like jXLS Reader. - rgettman
Cheers, went with a custom implementation in the end, that uses SAX to parse a config file of Field Names/Column mappings, then POI to create the POJOs. - Vvery similar to jXLS - anno_springer

1 Answers

-2
votes

Try this project, use meta(Meta.java) info to transform excel data to pojo. You can run TestConvert.java to see the operation.