瀏覽代碼

fix 导入Excel出现空行

周箭河 5 年之前
父節點
當前提交
9e6de3d701
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      edu-util/src/main/java/com/keao/edu/util/excel/POIUtil.java

+ 6 - 1
edu-util/src/main/java/com/keao/edu/util/excel/POIUtil.java

@@ -17,6 +17,7 @@ import java.util.Map.Entry;
 
 import org.apache.commons.beanutils.NestedNullException;
 import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFFont;
@@ -478,6 +479,7 @@ public class POIUtil {
 			rowIter = sheet.iterator();
 			while (rowIter.hasNext()) {
 				Map<String, Object> obj = null;
+				boolean hasVal = false;
 				// 获取当前行
 				row = rowIter.next();
 				if (row != null) {
@@ -511,11 +513,14 @@ public class POIUtil {
 						cell = cellIter.next();
 						cell.setCellType(Cell.CELL_TYPE_STRING);
 						String fieldValue = cell.getStringCellValue();
+						if(StringUtils.isNotBlank(fieldValue)){
+							hasVal  = true;
+						}
 						obj.put(fieldsName[currentCellNum], fieldValue);
 						currentCellNum++;
 					}
 				}
-				if (obj != null)
+				if (obj != null && hasVal)
 					datas.add(obj);
 
 			}