I'm using Apache POI to read an Excel document. I want to get the cell value from the next row if current is empty. For example, get from first row all not empty cell values and for empty cells: move to the next row and get the value. This the code I'm using to read the Excel document
//every sheet has rows, iterate over them
Iterator<Row> rowIterator = sheet.iterator();
if (rowIterator.hasNext())
rowIterator.next();
while (rowIterator.hasNext())
{
String libelle="";
.....
//Get the row object
Row row = rowIterator.next();
//Every row has columns, get the column iterator and iterate over them
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
//Get the Cell object
Cell cell = cellIterator.next();
//check the cell type and process accordingly
//2nd column
switch(cell.getCellType()){
case Cell.CELL_TYPE_STRING:
......
if (row.getCell(5) == null)
{
System.out.println("Cell is Empty in Column:" );
} else if (row.getCell(5).getCellType() == HSSFCell.CELL_TYPE_STRING)
{
libelle= row.getCell(5).getStringCellValue().trim();
}
...