From 971965ec5c16ffb5ab82ed29fa4f1a52dc3cb6ba Mon Sep 17 00:00:00 2001 From: jueyue Date: Wed, 10 Jun 2015 10:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AAtype?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B,String-Long=20=E7=B1=BB=E5=9E=8B,=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E7=A7=91=E5=AD=A6=E8=AE=B0=E6=95=B0=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E5=9D=91=E7=88=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poi/excel/annotation/Excel.java | 2 +- .../poi/excel/imports/CellValueServer.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java b/easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java index 80fee12..8093de7 100644 --- a/easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java +++ b/easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java @@ -107,7 +107,7 @@ public @interface Excel { public String savePath() default "upload"; /** - * 导出类型 1 是文本 2 是图片,3是函数 默认是文本 + * 导出类型 1 是文本 2 是图片,3是函数 默认是文本 ,4 String-Long型 */ public int type() default 1; diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java index aae3d7a..9b80a3d 100644 --- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java +++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java @@ -72,7 +72,7 @@ public class CellValueServer { result = getDateData(entity, cell.getStringCellValue()); } if (("class java.sql.Time").equals(xclass)) { - result = new Time(((Date)result).getTime()); + result = new Time(((Date) result).getTime()); } } else if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { result = cell.getNumericCellValue(); @@ -131,7 +131,7 @@ public class CellValueServer { result = replaceValue(entity.getReplace(), result); } result = hanlderValue(dataHanlder, object, result, titleString); - return getValueByType(xclass, result); + return getValueByType(xclass, result, entity); } /** @@ -155,7 +155,7 @@ public class CellValueServer { result = hanlderSuffix(entity.getSuffix(), result); result = replaceValue(entity.getReplace(), result); result = hanlderValue(dataHanlder, object, result, titleString); - return getValueByType(xclass, result); + return getValueByType(xclass, result, entity); } /** @@ -177,9 +177,10 @@ public class CellValueServer { * * @param xclass * @param result + * @param entity * @return */ - private Object getValueByType(String xclass, Object result) { + private Object getValueByType(String xclass, Object result, ExcelImportEntity entity) { try { if ("class java.util.Date".equals(xclass)) { return result; @@ -203,6 +204,14 @@ public class CellValueServer { return new BigDecimal(String.valueOf(result)); } if ("class java.lang.String".equals(xclass)) { + //针对String 类型,但是Excel获取的数据却不是String,比如Double类型,防止科学计数法 + if (result instanceof String) { + return result; + } + // 想要的结果是long + if (entity.getType() == 4 && result instanceof Double) { + result = String.valueOf(((Double) result).longValue()); + } return String.valueOf(result); } return result;