|
@@ -1,5 +1,6 @@
|
|
package cn.com.qmth.print.manage.utils.excel;
|
|
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.openxml4j.exceptions.InvalidFormatException;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
|
@@ -57,13 +58,27 @@ public class ExcelReader extends ExcelUtils {
|
|
}
|
|
}
|
|
Object dto = getDataClass().newInstance();
|
|
Object dto = getDataClass().newInstance();
|
|
// FieldAccess access = FieldAccess.get(getDataClass());
|
|
// 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);
|
|
ExcelError error = handle.handle(dto);
|
|
if (error != null) {
|
|
if (error != null) {
|