Bladeren bron

excel类型修改

wangliang 4 jaren geleden
bovenliggende
commit
a5ccb6e345

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/util/ExcelCallback.java

@@ -19,7 +19,8 @@ public interface ExcelCallback {
      *
      * @param finalList
      * @param finalColumnNameList
-     * @throws IllegalAccessException ß
+     * @return
+     * @throws IllegalAccessException
      */
     public List<LinkedMultiValueMap<Integer, Object>> callback(List<LinkedMultiValueMap<Integer, Object>> finalList, List<LinkedMultiValueMap<Integer, String>> finalColumnNameList) throws IllegalAccessException, IOException;
 }

+ 3 - 1
themis-business/src/main/java/com/qmth/themis/business/util/ExcelError.java

@@ -1,5 +1,7 @@
 package com.qmth.themis.business.util;
 
+import java.io.Serializable;
+
 /**
  * @Description: excel导入错误
  * @Param:
@@ -7,7 +9,7 @@ package com.qmth.themis.business.util;
  * @Author: wangliang
  * @Date: 2020/5/20
  */
-public class ExcelError {
+public class ExcelError implements Serializable {
 
     /**
      * 错误行数

+ 14 - 9
themis-business/src/main/java/com/qmth/themis/business/util/ExcelUtil.java

@@ -36,9 +36,10 @@ public class ExcelUtil {
      * @param clazz
      * @param callback
      * @return
+     * @throws NoSuchFieldException
      * @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;
         try {
             log.info("开始读取excel里的数据");
@@ -122,7 +123,7 @@ public class ExcelUtil {
         } catch (Exception e) {
             log.error("excel读取报错", e);
             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) {
                     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());
@@ -149,13 +150,17 @@ public class ExcelUtil {
      * @return
      */
     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;
     }