fix: 识别 excel 类型

This commit is contained in:
taojinlong 2021-07-30 12:27:14 +08:00
parent 0ab579b4fe
commit 577fa304f0
3 changed files with 16 additions and 8 deletions

View File

@ -68,6 +68,6 @@ public class ExcelReaderUtil {
}
public static void main(String[] args) throws Exception {
ExcelReaderUtil.readExcel("111.xls", new FileInputStream("/Users/taojinlong/Desktop/111.xls"));
ExcelReaderUtil.readExcel("跑步数据汇总——万马奔腾版0729.xlsx", new FileInputStream("/Users/taojinlong/Desktop/跑步数据汇总——万马奔腾版0729.xlsx"));
}
}

View File

@ -327,7 +327,7 @@ public class ExcelXlsxReader extends DefaultHandler {
formatString = style.getDataFormatString();
short format = this.formatIndex;
if (format == 14 || format == 31 || format == 57 ||format == 59||
format == 58 || (176 <= format && format <= 178)
format == 58 || (176 < format && format < 178)
|| (182 <= format && format <= 196) ||
(210 <= format && format <= 213) || (208 == format))
{ // 日期
@ -380,7 +380,7 @@ public class ExcelXlsxReader extends DefaultHandler {
break;
case NUMBER: //数字
if (formatString != null) {
if (formatString != null && isDateFormat) {
thisStr = formatter.formatRawCellContents(Double.parseDouble(value), formatIndex, formatString).trim();
} else {
thisStr = value;
@ -404,7 +404,7 @@ public class ExcelXlsxReader extends DefaultHandler {
}
if(curRow==1){
TableFiled tableFiled = new TableFiled();
tableFiled.setFieldType(type);
tableFiled.setFieldType("TEXT");
tableFiled.setFieldSize(65533);
tableFiled.setFieldName(thisStr);
tableFiled.setRemarks(thisStr);
@ -413,8 +413,16 @@ public class ExcelXlsxReader extends DefaultHandler {
if(CollectionUtils.isEmpty(this.getFields())){
throw new RuntimeException(Translator.get("i18n_excel_header_empty"));
}
if(type.equalsIgnoreCase("LONG") && this.getFields().get(curCol).getFieldType().equalsIgnoreCase("TEXT")){
this.getFields().get(curCol).setFieldType(type);
}
if(type.equalsIgnoreCase("DOUBLE") && !this.getFields().get(curCol).getFieldType().equalsIgnoreCase("DATETIME")){
this.getFields().get(curCol).setFieldType(type);
}
if(type.equalsIgnoreCase("DATETIME")){
this.getFields().get(curCol).setFieldType(type);
}
}
return thisStr;
}
@ -428,9 +436,7 @@ public class ExcelXlsxReader extends DefaultHandler {
thisStr = String.valueOf(Double.valueOf(thisStr)/100);
}
Long.valueOf(thisStr);
if(this.getFields().get(curCol).getFieldType().equalsIgnoreCase("TEXT")){
return "LONG";
}
}catch (Exception e){
try {
Double.valueOf(thisStr);

View File

@ -236,6 +236,7 @@ export default {
this.tableData = []
if (this.currGroup) {
this.dsLoading = true
this.tables = [];
post('/dataset/table/list', {
sort: 'type asc,name asc,create_time desc',
sceneId: this.currGroup.id,
@ -351,6 +352,7 @@ export default {
if (!this.isTreeSearch) {
if (node.data.id) {
this.dsLoading = true
this.tables = [];
post('/dataset/table/listAndGroup', {
sort: 'type asc,name asc,create_time desc',
sceneId: node.data.id,