Kaynağa Gözat

加了一个numformat

4.1.3.A
jueyue 7 yıl önce
ebeveyn
işleme
04a9422567
5 değiştirilmiş dosya ile 50 ekleme ve 10 silme
  1. +4
    -0
      easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java
  2. +10
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java
  3. +10
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java
  4. +24
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportBase.java
  5. +2
    -2
      gradle/wrapper/gradle-wrapper.properties

+ 4
- 0
easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java Dosyayı Görüntüle

@@ -43,6 +43,10 @@ public @interface Excel {
* 时间格式,相当于同时设置了exportFormat 和 importFormat
*/
public String format() default "";
/**
* 数字格式化,参数是Pattern,使用的对象是DecimalFormat
*/
public String numFormat() default "";
/**
* 导出时在excel中每个列的高度 单位为字符,一个汉字=2个字符


+ 10
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java Dosyayı Görüntüle

@@ -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;
}
}

+ 10
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java Dosyayı Görüntüle

@@ -70,6 +70,8 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
*/
private boolean isStatistics;
private String numFormat;
private List<ExcelExportEntity> list;
public ExcelExportEntity() {
@@ -187,6 +189,14 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
this.isStatistics = isStatistics;
}
public String getNumFormat() {
return numFormat;
}
public void setNumFormat(String numFormat) {
this.numFormat = numFormat;
}
@Override
public int compareTo(ExcelExportEntity prev) {
return this.getOrderNum() - prev.getOrderNum();


+ 24
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportBase.java Dosyayı Görüntüle

@@ -18,6 +18,7 @@ package cn.afterturn.easypoi.excel.export.base;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -28,6 +29,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +44,7 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
import cn.afterturn.easypoi.util.PoiReflectorUtil;
/**
* 导出基础处理,不设计POI,只设计对象,保证复用性
* 导出基础处理,不涉及POI,只涉及对象,保证复用性
*
* @author JueYue
* 2014年8月9日 下午11:01:32
@@ -83,7 +85,7 @@ public class ExportBase {
return excelEntity;
}
private Object formatValue(Object value, ExcelExportEntity entity) throws Exception {
private Object dateFormatValue(Object value, ExcelExportEntity entity) throws Exception {
Date temp = null;
if (value instanceof String) {
SimpleDateFormat format = new SimpleDateFormat(entity.getDatabaseFormat());
@@ -98,6 +100,20 @@ public class ExportBase {
return value;
}
private Object numFormatValue(Object value, ExcelExportEntity entity) {
if(value == null){
return null;
}
if(!NumberUtils.isNumber(value.toString())){
LOGGER.error("data want num format ,but is not num, value is:"+value);
return null;
}
Double d = Double.parseDouble(value.toString());
DecimalFormat df = new DecimalFormat(entity.getNumFormat());
return df.format(d);
}
/**
* 获取需要导出的全部字段
*
@@ -176,11 +192,14 @@ public class ExportBase {
: entity.getMethod().invoke(obj, new Object[] {});
}
if (StringUtils.isNotEmpty(entity.getFormat())) {
value = formatValue(value, entity);
value = dateFormatValue(value, entity);
}
if (entity.getReplace() != null && entity.getReplace().length > 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());
}
/**


+ 2
- 2
gradle/wrapper/gradle-wrapper.properties Dosyayı Görüntüle

@@ -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

Yükleniyor…
İptal
Kaydet