Przeglądaj źródła

调试Bug修改

xiaof 3 lat temu
rodzic
commit
e68ba13941

+ 22 - 7
src/main/java/cn/com/qmth/print/manage/utils/excel/ExcelReader.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.print.manage.utils.excel;
 
+import com.qmth.boot.core.exception.StatusException;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
 
@@ -57,13 +58,27 @@ public class ExcelReader extends ExcelUtils {
 				}
 				Object dto = getDataClass().newInstance();
 //				FieldAccess access = FieldAccess.get(getDataClass());
-				for (int j = 0; j < this.getColumnSettings().size(); j++) {
-					ColumnSetting columnSetting = this.getColumnSettings().get(j);
-					Cell cell = row.getCell(columnSetting.getIndex() - 1);
-					Object obj = convert(cell);
-					Field field = getDataClass().getDeclaredField(columnSetting.getFieldName());
-					field.setAccessible(true);
-					field.set(dto, obj);
+				try {
+					for (int j = 0; j < this.getColumnSettings().size(); j++) {
+						ColumnSetting columnSetting = this.getColumnSettings().get(j);
+						Cell cell = row.getCell(columnSetting.getIndex() - 1);
+						Object obj = convert(cell);
+						Field field = getDataClass().getDeclaredField(columnSetting.getFieldName());
+						field.setAccessible(true);
+						field.set(dto, obj);
+					}
+				} catch (NoSuchFieldException e) {
+					e.printStackTrace();
+				} catch (SecurityException e) {
+					e.printStackTrace();
+				} catch (IllegalArgumentException e) {
+					ExcelError error = new ExcelError();
+					error.setRow(i+1);
+					error.setExcelErrorType("数据格式有误,请转成文本格式");
+					excelErrors.add(error);
+					return excelErrors;
+				} catch (IllegalAccessException e) {
+					e.printStackTrace();
 				}
 				ExcelError error = handle.handle(dto);
 				if (error != null) {