Эх сурвалжийг харах

3.2.2-excel导入去除空行

xiaof 2 жил өмнө
parent
commit
cf58dabb00

+ 5 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ExcelUtil.java

@@ -156,6 +156,7 @@ public class ExcelUtil {
                             throw ExceptionResultEnum.ERROR.exception("导入文件和模版不一致");
                         }
                         boolean extend = fields[fields.length - 1].getName().contains(SystemConstant.EXTEND_COLUMN);
+                        int emptyRowSum = 0;
                         for (int j = firstcell; j < lastcell; j++) {
                             //获取第j列
                             Cell cell = row.getCell(j);
@@ -164,6 +165,9 @@ public class ExcelUtil {
                             } else {
                                 if (Objects.nonNull(cell)) {
                                     Object obj = convert(cell);
+                                    if (StringUtils.isBlank(obj.toString().trim())) {
+                                        emptyRowSum++;
+                                    }
                                     if (extend) {
                                         if (j < fields.length - 1) {
                                             fields[j].setAccessible(true);
@@ -202,7 +206,7 @@ public class ExcelUtil {
                                 }
                             }
                         }
-                        if (i > 0) {
+                        if (i > 0 && emptyRowSum - (lastcell - firstcell) != 0) {
                             oList.add(y, o);
                         }
                     }