Apache POI缺少单元格策略会跳过最后一个单元格,如果为空

时间:2016-03-22 08:10:45

标签: java excel apache-poi

我编写了一个片段来读取Excel值并在Java中进行操作。如果任何行的最后一个单元格为空,则不会被读取。

       while (rows.hasNext()) {
            Map<Integer, Object> columnDataMap = new HashMap<Integer, Object>();

            row = (XSSFRow) rows.next();

            for (int i = 0; i < row.getLastCellNum(); i++) {
                cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK);
                short fontIndex = cell.getCellStyle().getFontIndex();
                Font f = wb.getFontAt(fontIndex);

                if(cell.getCellType()==Cell.CELL_TYPE_BLANK){
                      columnDataMap.put(cell.getColumnIndex(), WFMTConstants.EMPTY_STRING);
                  }

                if (!(f.getBoldweight() == Font.BOLDWEIGHT_BOLD) ){

                columnDataMap.put(cell.getColumnIndex(), cell.toString());
                }
            }
            rowDataMap.put(row.getRowNum(), columnDataMap);
           }

如果它是空的,如何确保读取最后一个单元格?如果所有行通常具有7列并且例如。第3行有6列,第7行是空的,第7行也应该读为null但是对于那行row.getLastCellNum()返回6。

0 个答案:

没有答案
相关问题