Browse Source

新增一个type类型,String-Long 类型,防止科学记数法的坑爹问题

4.1.3.A
jueyue 10 years ago
parent
commit
971965ec5c
2 changed files with 14 additions and 5 deletions
  1. +1
    -1
      easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java
  2. +13
    -4
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java

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

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


+ 13
- 4
easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/CellValueServer.java View File

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


Loading…
Cancel
Save