Commit 8dd3ca5bb6b48e73f748ff4770f223b63cc09548
1 parent
be778ba3
excel 导入数字不需要格式化 ,导入允许列和属性个数不一致。
Showing
1 changed file
with
14 additions
and
10 deletions
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
| ... | ... | @@ -8,7 +8,6 @@ import java.io.OutputStream; |
| 8 | 8 | import java.lang.reflect.Field; |
| 9 | 9 | import java.lang.reflect.Method; |
| 10 | 10 | import java.math.BigDecimal; |
| 11 | -import java.text.DecimalFormat; | |
| 12 | 11 | import java.util.ArrayList; |
| 13 | 12 | import java.util.Arrays; |
| 14 | 13 | import java.util.Comparator; |
| ... | ... | @@ -18,6 +17,7 @@ import java.util.List; |
| 18 | 17 | import java.util.Map; |
| 19 | 18 | import java.util.UUID; |
| 20 | 19 | import java.util.stream.Collectors; |
| 20 | + | |
| 21 | 21 | import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
| 22 | 22 | import org.apache.poi.ss.usermodel.BorderStyle; |
| 23 | 23 | import org.apache.poi.ss.usermodel.Cell; |
| ... | ... | @@ -41,6 +41,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| 41 | 41 | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| 42 | 42 | import org.slf4j.Logger; |
| 43 | 43 | import org.slf4j.LoggerFactory; |
| 44 | + | |
| 44 | 45 | import com.ruoyi.common.annotation.Excel; |
| 45 | 46 | import com.ruoyi.common.annotation.Excel.ColumnType; |
| 46 | 47 | import com.ruoyi.common.annotation.Excel.Type; |
| ... | ... | @@ -200,7 +201,9 @@ public class ExcelUtil<T> |
| 200 | 201 | // 设置类的私有字段属性可访问. |
| 201 | 202 | field.setAccessible(true); |
| 202 | 203 | Integer column = cellMap.get(attr.name()); |
| 203 | - fieldsMap.put(column, field); | |
| 204 | + if(column !=null ) { // 字段在excel 中没有,那么就不需要设置值 | |
| 205 | + fieldsMap.put(column, field); | |
| 206 | + } | |
| 204 | 207 | } |
| 205 | 208 | } |
| 206 | 209 | for (int i = 1; i < rows; i++) |
| ... | ... | @@ -875,14 +878,15 @@ public class ExcelUtil<T> |
| 875 | 878 | } |
| 876 | 879 | else |
| 877 | 880 | { |
| 878 | - if ((Double) val % 1 > 0) | |
| 879 | - { | |
| 880 | - val = new DecimalFormat("0.00").format(val); | |
| 881 | - } | |
| 882 | - else | |
| 883 | - { | |
| 884 | - val = new DecimalFormat("0").format(val); | |
| 885 | - } | |
| 881 | + /* if ((Double) val % 1 > 0) | |
| 882 | + { | |
| 883 | + val = new DecimalFormat("0.00").format(val); | |
| 884 | + } | |
| 885 | + else | |
| 886 | + { | |
| 887 | + val = new DecimalFormat("0").format(val); | |
| 888 | + }*/ | |
| 889 | + val = new BigDecimal(val.toString()); // 导入的数据保证原汁原味,不做处理 | |
| 886 | 890 | } |
| 887 | 891 | } |
| 888 | 892 | else if (cell.getCellTypeEnum() == CellType.STRING) | ... | ... |