提交 abb8dcf3 authored 作者: taojinlong's avatar taojinlong

fix: 识别 Excel 字段类型

上级 982a7579
......@@ -44,6 +44,7 @@ import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -819,8 +820,15 @@ public class DataSetTableService {
} else if (cellTypeEnum.equals(CellType.NUMERIC)) {
double d = cell.getNumericCellValue();
try {
String value = String.valueOf(d);
return value.endsWith(".0") ? value.substring(0, value.length() -2):value;
Double value = new Double(d);
double eps = 1e-10;
if(value - Math.floor(value) < eps){
return value.longValue() + "";
}else {
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
return nf.format(value);
}
} catch (Exception e) {
BigDecimal b = new BigDecimal(d);
return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
......
......@@ -639,7 +639,7 @@ public class ExtractDataService {
private static String handleExcelIntColumn = " \t\tif(tmp != null && tmp.endsWith(\".0\")){\n" +
" try {\n" +
" Integer.valueOf(tmp.substring(0, tmp.length()-2));\n" +
" Long.valueOf(tmp.substring(0, tmp.length()-2));\n" +
" get(Fields.Out, filed).setValue(r, tmp.substring(0, tmp.length()-2));\n" +
" get(Fields.Out, filed).getValueMeta().setType(2);\n" +
" }catch (Exception e){}\n" +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论