Capture only one line of an Excel spreadsheet with POI

Asked

Viewed 11 times

0

Hello, everybody!

I have a system that needs to validate the type of cell contents of a spreadsheet line. I wish it was just a line, to avoid going through all the lines in the file, to avoid excessive processing. I have this code to go through the file:

while (rowIterator.hasNext()) {
        Row row = (Row) rowIterator.next();

        // Descantando a primeira linha com o header
        if (row.getRowNum() == 0) {
            continue;
        }

        Iterator cellIterator = row.cellIterator();
        ItemExcel item = new ItemExcel();
        itens.add(item);

        while (cellIterator.hasNext()) {
            Cell cell = (Cell) cellIterator.next();

            switch (cell.getColumnIndex()) {
            case 0:
                item.setDado0((int) cell.getNumericCellValue());
                break;
            case 1:
                item.setDado1(formatter.formatCellValue(cell));
                break;
            case 2:
                item.setDado2(formatter.formatCellValue(cell));
                break;
            case 3:
                item.setDado3(formatter.formatCellValue(cell));
                break;
            case 4:
                item.setDado4(formatter.formatCellValue(cell));
                break;
            case 5:
                item.setDado5(cell.getNumericCellValue());
                break;
            }
        }
    }

But I only need to validate one-line cells. How would I do that?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.