Java excel: Get next non-nullable cell in the same row

388 views Asked by At

I need help... after iterate through all rows and cells in excel, and finding a string (code below is from here), i need to find next value in the same row, but next value isn't in the next cell (the next few cells is empty)...

Here is the code for searching excel for a certain value:

 Iterator<Row> itr = sheet.iterator();
    while (itr.hasNext()) {
        Row row = itr.next();
        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                if (cell.getRichStringCellValue().getString().trim()
                        .equals(cellContent)) {

// after find a string (cellContent), I need a value of next not empty cell in the same row...

If I use

cell = cellIterator.next();

after finding string, to positioning to the next cell in row, the exception will occur because cell is empty.

So, I don't know how to search through non-empty cells in the same row in which I founded a certain string.

Tbank you.

0

There are 0 answers