|
@@ -1,5 +1,9 @@
|
|
package cn.com.qmth.examcloud.core.questions.base.excel;
|
|
package cn.com.qmth.examcloud.core.questions.base.excel;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -9,20 +13,6 @@ import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
-import org.apache.poi.ss.usermodel.DateUtil;
|
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
-import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.excel.ColumnSetting;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.excel.ExcelError;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.excel.ExcelReaderHandle;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.excel.ExcelUtils;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @author ting.yin
|
|
* @author ting.yin
|
|
* @Description: 读取excel
|
|
* @Description: 读取excel
|
|
@@ -30,7 +20,7 @@ import cn.com.qmth.examcloud.core.questions.base.excel.ExcelUtils;
|
|
*/
|
|
*/
|
|
public class ExcelReader extends ExcelUtils {
|
|
public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
- private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
+ private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
public ExcelReader(Class<?> dataClass) {
|
|
public ExcelReader(Class<?> dataClass) {
|
|
super(dataClass, true);
|
|
super(dataClass, true);
|
|
@@ -110,7 +100,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return (int) cell.getNumericCellValue();
|
|
return (int) cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive() && field.getType().getName().equals("int")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(int.class)) {
|
|
|
|
|
|
return (int) cell.getNumericCellValue();
|
|
return (int) cell.getNumericCellValue();
|
|
|
|
|
|
@@ -118,7 +108,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return (long) cell.getNumericCellValue();
|
|
return (long) cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive() && field.getType().getName().equals("long")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(long.class)) {
|
|
|
|
|
|
return (long) cell.getNumericCellValue();
|
|
return (long) cell.getNumericCellValue();
|
|
|
|
|
|
@@ -126,7 +116,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return (short) cell.getNumericCellValue();
|
|
return (short) cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive() && field.getType().getName().equals("short")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(short.class)) {
|
|
|
|
|
|
return (short) cell.getNumericCellValue();
|
|
return (short) cell.getNumericCellValue();
|
|
|
|
|
|
@@ -134,7 +124,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return (float) cell.getNumericCellValue();
|
|
return (float) cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive() && field.getType().getName().equals("float")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(float.class)) {
|
|
|
|
|
|
return (float) cell.getNumericCellValue();
|
|
return (float) cell.getNumericCellValue();
|
|
|
|
|
|
@@ -142,7 +132,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return (byte) cell.getNumericCellValue();
|
|
return (byte) cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive() && field.getType().getName().equals("byte")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(byte.class)) {
|
|
|
|
|
|
return (byte) cell.getNumericCellValue();
|
|
return (byte) cell.getNumericCellValue();
|
|
|
|
|
|
@@ -150,8 +140,7 @@ public class ExcelReader extends ExcelUtils {
|
|
|
|
|
|
return cell.getNumericCellValue();
|
|
return cell.getNumericCellValue();
|
|
|
|
|
|
- } else if (field.getType().isPrimitive()
|
|
|
|
- && field.getType().getName().equals("double")) {
|
|
|
|
|
|
+ } else if (field.getType().isAssignableFrom(double.class)) {
|
|
|
|
|
|
return cell.getNumericCellValue();
|
|
return cell.getNumericCellValue();
|
|
|
|
|
|
@@ -161,12 +150,16 @@ public class ExcelReader extends ExcelUtils {
|
|
if (numStr.contains("E")) {
|
|
if (numStr.contains("E")) {
|
|
numStr = new BigDecimal(numStr.trim()).toPlainString();
|
|
numStr = new BigDecimal(numStr.trim()).toPlainString();
|
|
}
|
|
}
|
|
- if (numStr.endsWith(".0"))
|
|
|
|
|
|
+
|
|
|
|
+ if (numStr.endsWith(".0")) {
|
|
numStr = numStr.substring(0, numStr.indexOf(".0"));
|
|
numStr = numStr.substring(0, numStr.indexOf(".0"));
|
|
|
|
+ }
|
|
|
|
+
|
|
return numStr;
|
|
return numStr;
|
|
} else {
|
|
} else {
|
|
return cell.getNumericCellValue();
|
|
return cell.getNumericCellValue();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+}
|