I want to convert excel to xml.Can any one tell me how to proceed with mapper? My code:
public class WorkGroupReader implements ItemReader<List<String>> {
WorkGroupMapper linemapper;
public void setLinemapper(WorkGroupMapper linemapper) {
this.linemapper = linemapper;
}
@Override
public List<String> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException,BiffException, IOException {
String FilePath = "E:\\ide-workspaces\\OmniFeed\\input\\WorkGroup.xls";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);
// TO get the access to the sheet
Sheet sh = wb.getSheet("WorkGroup");
// To get the number of rows present in sheet
int totalNoOfRows = sh.getRows();
// To get the number of columns present in sheet
int totalNoOfCols = sh.getColumns();
List<String> list=new ArrayList<String>();
for (int row = 1; row < totalNoOfRows; row++) {
for (int col = 1; col < totalNoOfCols; col++) {
//System.out.print(sh.getCell(col, row).getContents() + "\t");
list.add(sh.getCell(col, row).getContents());
//return linemapper.mapLine(sh.getCell(col, row).getContents(), 0);
}
}
return list;
i do not understand how to map with reader?
You can use Apache POI library to read .xls or .xlsx
For Maven projects: Add the following dependency to your project’s pom.xml file:
Here is an example code using XSSF
You don't map with reader.
You read into / as an in-memory data structure, and then write out the data structure as XML. Assuming that is what you are trying to do here.
(You could also do it incrementally, but lets not complicate things.)