提交者
Gitee
!48 ExcelUtil 功能优化
Merge pull request !48 from soulCoke/master
正在显示
1 个修改的文件
包含
7 行增加
和
3 行删除
| @@ -8,7 +8,6 @@ import java.io.OutputStream; | @@ -8,7 +8,6 @@ import java.io.OutputStream; | ||
| 8 | import java.lang.reflect.Field; | 8 | import java.lang.reflect.Field; |
| 9 | import java.lang.reflect.Method; | 9 | import java.lang.reflect.Method; |
| 10 | import java.math.BigDecimal; | 10 | import java.math.BigDecimal; |
| 11 | -import java.text.DecimalFormat; | ||
| 12 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
| 13 | import java.util.Arrays; | 12 | import java.util.Arrays; |
| 14 | import java.util.Comparator; | 13 | import java.util.Comparator; |
| @@ -18,6 +17,7 @@ import java.util.List; | @@ -18,6 +17,7 @@ import java.util.List; | ||
| 18 | import java.util.Map; | 17 | import java.util.Map; |
| 19 | import java.util.UUID; | 18 | import java.util.UUID; |
| 20 | import java.util.stream.Collectors; | 19 | import java.util.stream.Collectors; |
| 20 | + | ||
| 21 | import org.apache.poi.hssf.usermodel.HSSFDateUtil; | 21 | import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
| 22 | import org.apache.poi.ss.usermodel.BorderStyle; | 22 | import org.apache.poi.ss.usermodel.BorderStyle; |
| 23 | import org.apache.poi.ss.usermodel.Cell; | 23 | import org.apache.poi.ss.usermodel.Cell; |
| @@ -41,6 +41,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; | @@ -41,6 +41,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; | ||
| 41 | import org.apache.poi.xssf.usermodel.XSSFDataValidation; | 41 | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| 42 | import org.slf4j.Logger; | 42 | import org.slf4j.Logger; |
| 43 | import org.slf4j.LoggerFactory; | 43 | import org.slf4j.LoggerFactory; |
| 44 | + | ||
| 44 | import com.ruoyi.common.annotation.Excel; | 45 | import com.ruoyi.common.annotation.Excel; |
| 45 | import com.ruoyi.common.annotation.Excel.ColumnType; | 46 | import com.ruoyi.common.annotation.Excel.ColumnType; |
| 46 | import com.ruoyi.common.annotation.Excel.Type; | 47 | import com.ruoyi.common.annotation.Excel.Type; |
| @@ -200,9 +201,11 @@ public class ExcelUtil<T> | @@ -200,9 +201,11 @@ public class ExcelUtil<T> | ||
| 200 | // 设置类的私有字段属性可访问. | 201 | // 设置类的私有字段属性可访问. |
| 201 | field.setAccessible(true); | 202 | field.setAccessible(true); |
| 202 | Integer column = cellMap.get(attr.name()); | 203 | Integer column = cellMap.get(attr.name()); |
| 204 | + if(column !=null ) { // 字段在excel 中没有,那么就不需要设置值 | ||
| 203 | fieldsMap.put(column, field); | 205 | fieldsMap.put(column, field); |
| 204 | } | 206 | } |
| 205 | } | 207 | } |
| 208 | + } | ||
| 206 | for (int i = 1; i < rows; i++) | 209 | for (int i = 1; i < rows; i++) |
| 207 | { | 210 | { |
| 208 | // 从第2行开始取数据,默认第一行是表头. | 211 | // 从第2行开始取数据,默认第一行是表头. |
| @@ -894,14 +897,15 @@ public class ExcelUtil<T> | @@ -894,14 +897,15 @@ public class ExcelUtil<T> | ||
| 894 | } | 897 | } |
| 895 | else | 898 | else |
| 896 | { | 899 | { |
| 897 | - if ((Double) val % 1 > 0) | 900 | + /* if ((Double) val % 1 > 0) |
| 898 | { | 901 | { |
| 899 | val = new DecimalFormat("0.00").format(val); | 902 | val = new DecimalFormat("0.00").format(val); |
| 900 | } | 903 | } |
| 901 | else | 904 | else |
| 902 | { | 905 | { |
| 903 | val = new DecimalFormat("0").format(val); | 906 | val = new DecimalFormat("0").format(val); |
| 904 | - } | 907 | + }*/ |
| 908 | + val = new BigDecimal(val.toString()); // 导入的数据保证原汁原味,不做处理 | ||
| 905 | } | 909 | } |
| 906 | } | 910 | } |
| 907 | else if (cell.getCellTypeEnum() == CellType.STRING) | 911 | else if (cell.getCellTypeEnum() == CellType.STRING) |
-
请 注册 或 登录 后发表评论