forked from github/dataease
fix: 识别 Excel 字段类型
This commit is contained in:
parent
982a7579c8
commit
abb8dcf3c3
@ -44,6 +44,7 @@ import java.io.*;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -819,8 +820,15 @@ public class DataSetTableService {
|
|||||||
} else if (cellTypeEnum.equals(CellType.NUMERIC)) {
|
} else if (cellTypeEnum.equals(CellType.NUMERIC)) {
|
||||||
double d = cell.getNumericCellValue();
|
double d = cell.getNumericCellValue();
|
||||||
try {
|
try {
|
||||||
String value = String.valueOf(d);
|
Double value = new Double(d);
|
||||||
return value.endsWith(".0") ? value.substring(0, value.length() -2):value;
|
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) {
|
} catch (Exception e) {
|
||||||
BigDecimal b = new BigDecimal(d);
|
BigDecimal b = new BigDecimal(d);
|
||||||
return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
|
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" +
|
private static String handleExcelIntColumn = " \t\tif(tmp != null && tmp.endsWith(\".0\")){\n" +
|
||||||
" try {\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).setValue(r, tmp.substring(0, tmp.length()-2));\n" +
|
||||||
" get(Fields.Out, filed).getValueMeta().setType(2);\n" +
|
" get(Fields.Out, filed).getValueMeta().setType(2);\n" +
|
||||||
" }catch (Exception e){}\n" +
|
" }catch (Exception e){}\n" +
|
||||||
|
Loading…
Reference in New Issue
Block a user