Commit 55095a50b5df8b6207bc92fbcbc065c2bcd4ba7d
Committed by
Gitee
!48 ExcelUtil 功能优化
Merge pull request !48 from soulCoke/master
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++) |
| ... | ... | @@ -894,14 +897,15 @@ public class ExcelUtil<T> |
| 894 | 897 | } |
| 895 | 898 | else |
| 896 | 899 | { |
| 897 | - if ((Double) val % 1 > 0) | |
| 898 | - { | |
| 899 | - val = new DecimalFormat("0.00").format(val); | |
| 900 | - } | |
| 901 | - else | |
| 902 | - { | |
| 903 | - val = new DecimalFormat("0").format(val); | |
| 904 | - } | |
| 900 | + /* if ((Double) val % 1 > 0) | |
| 901 | + { | |
| 902 | + val = new DecimalFormat("0.00").format(val); | |
| 903 | + } | |
| 904 | + else | |
| 905 | + { | |
| 906 | + val = new DecimalFormat("0").format(val); | |
| 907 | + }*/ | |
| 908 | + val = new BigDecimal(val.toString()); // 导入的数据保证原汁原味,不做处理 | |
| 905 | 909 | } |
| 906 | 910 | } |
| 907 | 911 | else if (cell.getCellTypeEnum() == CellType.STRING) | ... | ... |