From 8dd3ca5bb6b48e73f748ff4770f223b63cc09548 Mon Sep 17 00:00:00 2001 From: soulCoke <296312250@qq.com> Date: Thu, 23 Jul 2020 15:54:03 +0800 Subject: [PATCH] =?UTF-8?q?excel=20=E5=AF=BC=E5=85=A5=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E6=A0=BC=E5=BC=8F=E5=8C=96=20?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E5=85=A5=E5=85=81=E8=AE=B8=E5=88=97=E5=92=8C?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=AA=E6=95=B0=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/poi/ExcelUtil.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index affb08f7..9e9932f6 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -8,7 +8,6 @@ import java.io.OutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -18,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; + import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.Cell; @@ -41,6 +41,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFDataValidation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel.ColumnType; import com.ruoyi.common.annotation.Excel.Type; @@ -200,7 +201,9 @@ public class ExcelUtil // 设置类的私有字段属性可访问. field.setAccessible(true); Integer column = cellMap.get(attr.name()); - fieldsMap.put(column, field); + if(column !=null ) { // 字段在excel 中没有,那么就不需要设置值 + fieldsMap.put(column, field); + } } } for (int i = 1; i < rows; i++) @@ -875,14 +878,15 @@ public class ExcelUtil } else { - if ((Double) val % 1 > 0) - { - val = new DecimalFormat("0.00").format(val); - } - else - { - val = new DecimalFormat("0").format(val); - } + /* if ((Double) val % 1 > 0) + { + val = new DecimalFormat("0.00").format(val); + } + else + { + val = new DecimalFormat("0").format(val); + }*/ + val = new BigDecimal(val.toString()); // 导入的数据保证原汁原味,不做处理 } } else if (cell.getCellTypeEnum() == CellType.STRING)