I'm trying to get the values of the cells that form a row of an excel document. The point is that I recover all of them in a row but I would like to recover the value of a specific cell.
I put the code here. Thanks in advance.
public void leerExcel(File excel){
List cellData = new ArrayList();
try{
FileInputStream fis = new FileInputStream(excel);
XSSFWorkbook workBook = new XSSFWorkbook(fis);
XSSFSheet hoja = workBook.getSheetAt(0);
Iterator rowIterator = hoja.rowIterator();
while (rowIterator.hasNext()){
XSSFRow row = (XSSFRow) rowIterator.next();
Iterator iterator = row.cellIterator();
List cellTemp = new ArrayList();
while(iterator.hasNext()){
XSSFCell cell = (XSSFCell) iterator.next();
cellTemp.add(cell);
}
cellData.add(cellTemp);
}
}catch (Exception ex){
System.out.println(ex.getMessage());
}
obtenerDatos(cellData);
}
public void obtenerDatos (List cellList){
for(int i=0; i<cellList.size(); i++){
List listado = (List) cellList.get(i);
for(int j=0;j<listado.size();j++){
XSSFCell celdas = (XSSFCell) listado.get(j);
String valor = celdas.toString();
System.out.print(valor+" ");
}
System.out.println();
}
}