|
@@ -152,7 +152,7 @@ public class ExcelUtil {
|
|
|
o = clazz.get(y).newInstance();
|
|
|
Field[] fields = o.getClass().getDeclaredFields();
|
|
|
ExcelImportTempleteVaild excelImportTempleteVaild = o.getClass().getDeclaredAnnotation(ExcelImportTempleteVaild.class);
|
|
|
- if (Objects.nonNull(excelImportTempleteVaild) && excelImportTempleteVaild.value() && lastcell > fields.length) {
|
|
|
+ if (Objects.nonNull(excelImportTempleteVaild) && excelImportTempleteVaild.value() && (lastcell > fields.length || sheets != clazz.size())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("导入文件和模版不一致");
|
|
|
}
|
|
|
boolean extend = fields[fields.length - 1].getName().contains(SystemConstant.EXTEND_COLUMN);
|
|
@@ -170,7 +170,7 @@ public class ExcelUtil {
|
|
|
fields[j].set(o, obj);
|
|
|
Annotation annotation = fields[j].getAnnotation(NotNull.class);
|
|
|
ExcelNote note = fields[j].getAnnotation(ExcelNote.class);
|
|
|
- if (Objects.isNull(obj) && Objects.nonNull(annotation)) {
|
|
|
+ if ((Objects.isNull(obj) || Objects.equals("", obj)) && Objects.nonNull(annotation)) {
|
|
|
excelErrorList.add(y, new ExcelError(j + 1, "excel第" + (y + 1) + "个sheet第" + (j + 1) + "行[" + note.value() + "]为空"));
|
|
|
}
|
|
|
} else {
|
|
@@ -193,7 +193,7 @@ public class ExcelUtil {
|
|
|
fields[j].set(o, obj);
|
|
|
Annotation annotation = fields[j].getAnnotation(NotNull.class);
|
|
|
ExcelNote note = fields[j].getAnnotation(ExcelNote.class);
|
|
|
- if (Objects.isNull(obj) && Objects.nonNull(annotation)) {
|
|
|
+ if ((Objects.isNull(obj) || Objects.equals("", obj)) && Objects.nonNull(annotation)) {
|
|
|
excelErrorList.add(y, new ExcelError(i + 1, "excel第" + (y + 1) + "个sheet第" + (i + 1) + "行[" + note.value() + "]为空"));
|
|
|
}
|
|
|
}
|
|
@@ -299,7 +299,7 @@ public class ExcelUtil {
|
|
|
field.setAccessible(true);
|
|
|
Annotation annotation = field.getAnnotation(NotNull.class);
|
|
|
ExcelNote note = field.getAnnotation(ExcelNote.class);
|
|
|
- if (Objects.isNull(field.get(obj)) && Objects.nonNull(annotation)) {
|
|
|
+ if ((Objects.isNull(field.get(obj)) || Objects.equals("", field.get(obj))) && Objects.nonNull(annotation)) {
|
|
|
excelErrorList.add(new ExcelError(index + 1, "excel第" + (sheetIndex + 1) + "个sheet第" + (index + 1) + "行[" + note.value() + "]为空"));
|
|
|
}
|
|
|
}
|
|
@@ -308,18 +308,19 @@ public class ExcelUtil {
|
|
|
|
|
|
/**
|
|
|
* 验证excel中某一行是否全部为空
|
|
|
- * @param row 当前行
|
|
|
+ *
|
|
|
+ * @param row 当前行
|
|
|
* @param firstRow 第一行标题行
|
|
|
* @return 是否整整一行为空
|
|
|
*/
|
|
|
- public static boolean isRowAllCellEmpty(Row row,Row firstRow) {
|
|
|
+ public static boolean isRowAllCellEmpty(Row row, Row firstRow) {
|
|
|
int count = 0;
|
|
|
//单元格数量
|
|
|
int rowCount = firstRow.getLastCellNum() - firstRow.getFirstCellNum();
|
|
|
//判断多少个单元格为空
|
|
|
for (int c = 0; c < rowCount; c++) {
|
|
|
Cell cell = row.getCell(c);
|
|
|
- if (cell == null || cell.getCellTypeEnum() == CellType.BLANK || StringUtils.isEmpty((cell+"").trim())){
|
|
|
+ if (cell == null || cell.getCellTypeEnum() == CellType.BLANK || StringUtils.isEmpty((cell + "").trim())) {
|
|
|
count += 1;
|
|
|
}
|
|
|
}
|