1 判断单个单元格为空
//判断单个单元格是否为空
public static boolean isEmptyCell(Cell cell){
if(cell==null||cell.getCellType().equals(CellType.BLANK)){
return true;
}
return false;
}
2 判断单行是否为空
/**
* 判断该行是否为空
* @param row 行对象
* @return
*/
public static boolean isEmptyRow(Row row){
//行不存在
if (row == null) {
return true;
}
//第一个列位置
int firstCellNum = row.getFirstCellNum();
//最后一列位置
int lastCellNum = row.getLastCellNum();
//空列数量
int nullCellNum = 0;
for (int c = firstCellNum; c < lastCellNum; c++) {
Cell cell = row.getCell(c);
if (null == cell || CellType.BLANK == cell.getCellType()) {
nullCellNum ++;
continue;
}
cell.setCellType(CellType.STRING);
String cellValue = cell.getStringCellValue().trim();
if (StringUtils.isEmpty(cellValue)) {
nullCellNum ++;
}
}
//所有列都为空
if (nullCellNum == (lastCellNum - firstCellNum)) {
return true;
}
return false;
}