From 04a9422567c8e96f4907a25b883d56824507d326 Mon Sep 17 00:00:00 2001 From: jueyue Date: Sat, 17 Jun 2017 16:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AAnumformat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easypoi/excel/annotation/Excel.java | 4 +++ .../easypoi/excel/entity/ImportParams.java | 15 +++++++---- .../entity/params/ExcelExportEntity.java | 10 +++++++ .../easypoi/excel/export/base/ExportBase.java | 27 ++++++++++++++++--- gradle/wrapper/gradle-wrapper.properties | 4 +-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java b/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java index 1b423d1..f72c14b 100644 --- a/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java +++ b/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java @@ -43,6 +43,10 @@ public @interface Excel { * 时间格式,相当于同时设置了exportFormat 和 importFormat */ public String format() default ""; + /** + * 数字格式化,参数是Pattern,使用的对象是DecimalFormat + */ + public String numFormat() default ""; /** * 导出时在excel中每个列的高度 单位为字符,一个汉字=2个字符 diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java index 7b6044a..7f53101 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java @@ -38,10 +38,13 @@ public class ImportParams extends ExcelBaseParams { * 字段真正值和列标题之间的距离 默认0 */ private int startRows = 0; + /** * 主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值 + * 大家不理解,去掉这个 */ - private Integer keyIndex = 0; + + private Integer keyIndex = null; /** * 开始读取的sheet位置,默认为0 */ @@ -84,10 +87,6 @@ public class ImportParams extends ExcelBaseParams { return headRows; } - public Integer getKeyIndex() { - return keyIndex; - } - public String getSaveUrl() { return saveUrl; } @@ -116,6 +115,7 @@ public class ImportParams extends ExcelBaseParams { this.headRows = headRows; } + @Deprecated public void setKeyIndex(Integer keyIndex) { this.keyIndex = keyIndex; } @@ -184,4 +184,9 @@ public class ImportParams extends ExcelBaseParams { this.readRows = readRows; } + public Integer getKeyIndex() { + return keyIndex; + } + + } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java index c958482..eabea73 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java @@ -70,6 +70,8 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable list; public ExcelExportEntity() { @@ -187,6 +189,14 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable 0) { value = replaceValue(entity.getReplace(), String.valueOf(value)); } + if (StringUtils.isNotEmpty(entity.getNumFormat())) { + value = numFormatValue(value, entity); + } if (needHanlderList != null && needHanlderList.contains(entity.getName())) { value = dataHanlder.exportHandler(obj, entity.getName(), value); } @@ -190,6 +209,7 @@ public class ExportBase { return value == null ? "" : value.toString(); } + /** * 获取集合的值 * @param entity @@ -237,6 +257,7 @@ public class ExportBase { excelEntity.setStatistics(excel.isStatistics()); excelEntity.setHyperlink(excel.isHyperlink()); excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); + excelEntity.setNumFormat(excel.numFormat()); } /** diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bee6378..2709e04 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Dec 15 22:20:53 CST 2015 +#Mon May 15 20:18:13 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip