|
@@ -36,9 +36,10 @@ public class ExcelUtil {
|
|
* @param clazz
|
|
* @param clazz
|
|
* @param callback
|
|
* @param callback
|
|
* @return
|
|
* @return
|
|
|
|
+ * @throws NoSuchFieldException
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public static List<LinkedMultiValueMap<Integer, Object>> excelReader(InputStream inputStream, List<Class<?>> clazz, ExcelCallback callback) throws IOException, NoSuchFieldException {
|
|
|
|
|
|
+ public static List<LinkedMultiValueMap<Integer, Object>> excelReader(InputStream inputStream, List<Class<?>> clazz, ExcelCallback callback) throws NoSuchFieldException, IOException {
|
|
Object o = null;
|
|
Object o = null;
|
|
try {
|
|
try {
|
|
log.info("开始读取excel里的数据");
|
|
log.info("开始读取excel里的数据");
|
|
@@ -122,7 +123,7 @@ public class ExcelUtil {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("excel读取报错", e);
|
|
log.error("excel读取报错", e);
|
|
if (e instanceof IllegalArgumentException) {
|
|
if (e instanceof IllegalArgumentException) {
|
|
- String errorColumn = e.getMessage().toString();
|
|
|
|
|
|
+ String errorColumn = e.getMessage();
|
|
if (errorColumn.indexOf("Can not set java.lang.String field") != -1 && errorColumn.indexOf("to java.lang.Long") != -1) {
|
|
if (errorColumn.indexOf("Can not set java.lang.String field") != -1 && errorColumn.indexOf("to java.lang.Long") != -1) {
|
|
String column = errorColumn.substring(errorColumn.indexOf("Can not set java.lang.String field") + 1, errorColumn.indexOf("to java.lang.Long"));
|
|
String column = errorColumn.substring(errorColumn.indexOf("Can not set java.lang.String field") + 1, errorColumn.indexOf("to java.lang.Long"));
|
|
column = column.substring(column.lastIndexOf(".") + 1, column.length());
|
|
column = column.substring(column.lastIndexOf(".") + 1, column.length());
|
|
@@ -149,13 +150,17 @@ public class ExcelUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
private static Object convert(Cell cell) {
|
|
private static Object convert(Cell cell) {
|
|
- switch (cell.getCellType()) {
|
|
|
|
- case Cell.CELL_TYPE_STRING:
|
|
|
|
- return String.valueOf(cell.getStringCellValue());
|
|
|
|
- case Cell.CELL_TYPE_BOOLEAN:
|
|
|
|
- return String.valueOf(cell.getBooleanCellValue());
|
|
|
|
- case Cell.CELL_TYPE_NUMERIC:
|
|
|
|
- return Math.round(cell.getNumericCellValue());
|
|
|
|
|
|
+ switch (cell.getCellTypeEnum()) {
|
|
|
|
+ case NUMERIC:
|
|
|
|
+ return cell.getNumericCellValue();
|
|
|
|
+ case STRING:
|
|
|
|
+ return cell.getStringCellValue();
|
|
|
|
+ case FORMULA:
|
|
|
|
+ return cell.getCellFormula();
|
|
|
|
+ case BOOLEAN:
|
|
|
|
+ return cell.getBooleanCellValue();
|
|
|
|
+ case ERROR:
|
|
|
|
+ return cell.getErrorCellValue();
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|