Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

java - Get only one line from a XLS file with POI

I need to check and validate the cells types from a single line in my XLS file. I like to read only one line, to avoid problems. Here's my code to read all the lines:

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 need to only check a single line, how can I do this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...