Browse Source

增加,后缀选项,修改了map的bug

4.1.3.A
jueyue 10 years ago
parent
commit
eb6a9c3faf
4 changed files with 33 additions and 12 deletions
  1. +4
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java
  2. +16
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelExportEntity.java
  3. +12
    -11
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExportBase.java
  4. +1
    -1
      easypoi-test/src/main/java/org/jeecgframework/poi/entity/StudentEntity.java

+ 4
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java View File

@@ -47,6 +47,10 @@ public @interface Excel {
* 导入的时间格式,以这个是否为空来判断是否需要格式化日期 * 导入的时间格式,以这个是否为空来判断是否需要格式化日期
*/ */
public String importFormat() default ""; public String importFormat() default "";
/**
* 文字后缀,如% 90 变成90%
*/
public String suffix() default "";
/** /**
* 是否换行 即支持\n * 是否换行 即支持\n


+ 16
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelExportEntity.java View File

@@ -50,13 +50,21 @@ public class ExcelExportEntity extends ExcelBaseEntity {
* cell 函数 * cell 函数
*/ */
private String cellFormula; private String cellFormula;
/**
* 后缀
*/
private String suffix;
private List<ExcelExportEntity> list; private List<ExcelExportEntity> list;
public ExcelExportEntity() { public ExcelExportEntity() {
} }
public ExcelExportEntity(String name) { public ExcelExportEntity(String name) {
super.name = name; super.name = name;
} }
public ExcelExportEntity(String name, Object key) { public ExcelExportEntity(String name, Object key) {
super.name = name; super.name = name;
this.key = key; this.key = key;
@@ -156,4 +164,12 @@ public class ExcelExportEntity extends ExcelBaseEntity {
this.isWrap = isWrap; this.isWrap = isWrap;
} }
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
} }

+ 12
- 11
easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExportBase.java View File

@@ -47,12 +47,7 @@ public class ExportBase {
throws Exception { throws Exception {
Excel excel = field.getAnnotation(Excel.class); Excel excel = field.getAnnotation(Excel.class);
ExcelExportEntity excelEntity = new ExcelExportEntity(); ExcelExportEntity excelEntity = new ExcelExportEntity();
try {
excelEntity.setType(excel.type());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
excelEntity.setType(excel.type());
getExcelField(targetId, field, excelEntity, excel, pojoClass); getExcelField(targetId, field, excelEntity, excel, pojoClass);
if (getMethods != null) { if (getMethods != null) {
List<Method> newMethods = new ArrayList<Method>(); List<Method> newMethods = new ArrayList<Method>();
@@ -162,18 +157,23 @@ public class ExportBase {
public Object getCellValue(ExcelExportEntity entity, Object obj) throws Exception { public Object getCellValue(ExcelExportEntity entity, Object obj) throws Exception {
Object value; Object value;
if (obj instanceof Map) { if (obj instanceof Map) {
return ((Map<?, ?>) obj).get(entity.getKey());
value = ((Map<?, ?>) obj).get(entity.getKey());
} else { } else {
value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj)
: entity.getMethod().invoke(obj, new Object[] {}); : entity.getMethod().invoke(obj, new Object[] {});
} }
if (needHanlderList != null && needHanlderList.contains(entity.getName())) {
value = dataHanlder.exportHandler(obj, entity.getName(), value);
} else if (StringUtils.isNotEmpty(entity.getFormat())) {
if (StringUtils.isNotEmpty(entity.getFormat())) {
value = formatValue(value, entity); value = formatValue(value, entity);
} else if (entity.getReplace() != null && entity.getReplace().length > 0) {
}
if (entity.getReplace() != null && entity.getReplace().length > 0) {
value = replaceValue(entity.getReplace(), String.valueOf(value)); value = replaceValue(entity.getReplace(), String.valueOf(value));
} }
if (needHanlderList != null && needHanlderList.contains(entity.getName())) {
value = dataHanlder.exportHandler(obj, entity.getName(), value);
}
if (StringUtils.isNotEmpty(entity.getSuffix()) && value != null) {
value = value + entity.getSuffix();
}
return value == null ? "" : value.toString(); return value == null ? "" : value.toString();
} }
@@ -199,6 +199,7 @@ public class ExportBase {
excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId)); excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId));
excelEntity.setWrap(excel.isWrap()); excelEntity.setWrap(excel.isWrap());
excelEntity.setExportImageType(excel.imageType()); excelEntity.setExportImageType(excel.imageType());
excelEntity.setSuffix(excel.suffix());
excelEntity.setDatabaseFormat(excel.databaseFormat()); excelEntity.setDatabaseFormat(excel.databaseFormat());
excelEntity.setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel.exportFormat() excelEntity.setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel.exportFormat()
: excel.format()); : excel.format());


+ 1
- 1
easypoi-test/src/main/java/org/jeecgframework/poi/entity/StudentEntity.java View File

@@ -25,7 +25,7 @@ public class StudentEntity implements java.io.Serializable {
/** /**
* 学生性别 * 学生性别
*/ */
@Excel(name = "学生性别", replace = { "男_1", "女_2" })
@Excel(name = "学生性别", replace = { "男_1", "女_2" },suffix = "生")
private int sex; private int sex;
@Excel(name = "出生日期", format = "yyyy-MM-dd HH:mm:ss", mergeVertical = true) @Excel(name = "出生日期", format = "yyyy-MM-dd HH:mm:ss", mergeVertical = true)


Loading…
Cancel
Save