过滤导入excel 空行问题
Sheet sheet = wb.getSheetAt(0);
CompanyInfoEntity companyEntity = null;
BuildingInfoEntity buildingEntity = null;
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
//获取索引为i的行,以0开始
Row row = sheet.getRow(i);
// 过滤掉空行
if (isEmptyRow(row)) {
continue;
}
// 检查行是否为空的方法
private boolean isEmptyRow(Row row) {
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
if (row.getCell(j) != null && !row.getCell(j).getStringCellValue().trim().isEmpty()) {
return false; // 至少有一个非空单元格,该行不为空
}
}
return true; // 所有单元格都为空,该行为空行
}