poi判断是否空行

发布时间 2023-04-18 15:41:41作者: 圣上有喜

空行现象:

  空行只解析出一个cell,并且type是STRING。与实际列数不符

解决方法:

  强制要求从第0列开始判断cell是否为null且type不为BLANK,否则即认为改行为空行并跳过处理

 1 /**
 2  * 校验是否为空行
 3  * 
 4  * @param row 行
 5  * @return 是否为空
 6  */
 7 public static boolean isEmptyRow(Row row) {
 8     if (row == null || row.toString().isEmpty()) {
 9         return true;
10     }
11     // 从第一列到最后一列都校验单元格类型是否为BLANK
12     for (int i = 0; i < row.getLastCellNum(); i++) {
13         final Cell cell = row.getCell(i);
14         if (cell == null || cell.getCellType() == CellType.BLANK) {
15             return true;
16         }
17     }
18     return flase;
19 }