首页 > 解决方案 > 如何在使用 POI 迭代 excel 文件时跳过空白单元格值并选择下一个单元格

问题描述

我正在尝试解析一个excel文件,我必须在其中并行读取标题和数据。我需要检查,如果找到空白单元格,则在解析标题时我必须立即跳过单元格并获取下一个值,但这不能在另一次迭代中完成。我在这里尝试过,但在我的代码中,我在跳过的单元格中没有得到任何值,

       while (cellIterator.hasNext() && cellIteratorTotal.hasNext()) {

            cellCount++;
            Cell currentCell = cellIterator.next();

            Cell currentCellTotal = cellIteratorTotal.next();

            currentRow =  sheet.getRow(currentRowTotal.getRowNum() + 1); // here i am trying to hold the current row value 

            String cellValue = excelManager.evalCell(currentCell);

            String cellValueTotal = excelManager.evalCell(currentCellTotal);
            if(currentRow!=null) {
                String value = currentRow.getCell(currentCellTotal.getColumnIndex(), Row.CREATE_NULL_AS_BLANK).getStringCellValue(); //  here i am trying to get the next cell value 
            }

任何人都可以帮助我正确的方法吗,在此先感谢

标签: javaexcelapacheapache-poi

解决方案


下面的代码可以帮助你。请检查。if (cell == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {

}


推荐阅读