From 38cd04700ba5d8b0b5489e56679a94bc6f448e0c Mon Sep 17 00:00:00 2001 From: Geequlim Date: Fri, 24 Jul 2020 15:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=BD=E7=95=A5=E8=A1=A8=E5=A4=96=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8E=A8=E6=96=AD=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E7=B1=BB=E5=9E=8B=E6=8F=90=E5=8D=87=E6=97=B6?= =?UTF-8?q?=E7=BB=99=E5=87=BA=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/excel-exporter/TableParser.ts | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/excel-exporter/TableParser.ts b/src/excel-exporter/TableParser.ts index ba1d945..8aabfb6 100644 --- a/src/excel-exporter/TableParser.ts +++ b/src/excel-exporter/TableParser.ts @@ -89,7 +89,7 @@ export class TableParser { } protected process_table(raw: RawTableData): TableData { - + const type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool, DataType.null]; let headers: ColumnDescription[] = []; let column_values: xlsl.CellObject[][] = []; @@ -109,17 +109,17 @@ export class TableParser { ignored_columns.add(c); continue; } - let column_cells = this.get_column(rows, c, 1); + const start_raw = 1; + let column_cells = this.get_column(rows, c, start_raw); let type = DataType.null; - let types = new Set(); - for (const cell of column_cells) { - types.add(this.get_data_type(cell)); - } - let type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool ]; - for (const t of type_order) { - if (types.has(t)) { + for (let i = 0; i < column_cells.length; i++) { + const cell = column_cells[i]; + var t = this.get_data_type(cell); + if (type_order.indexOf(t) < type_order.indexOf(type)) { + if (type != DataType.null) { + console.log(colors.yellow(`\t\t${first.v} 的数据类型被提升为 ${t}\n\t\t ${this.dump_row_values(rows[start_raw + i])}`)); + } type = t; - break; } } let comment: string = undefined; @@ -217,7 +217,11 @@ export class TableParser { } let all_empty = true; for (const cell of row) { - all_empty = all_empty && this.get_data_type(cell) == DataType.null; + let current_empty = this.get_data_type(cell) == DataType.null; + if (!current_empty) { + current_empty = this.get_data_type(cell) == DataType.string && (cell.v as string).trim().length == 0; + } + all_empty = all_empty && current_empty; } if (all_empty) return false; return true; @@ -263,4 +267,12 @@ export class TableParser { return null; } } + + protected dump_row_values(row: xlsl.CellObject[]) { + let ret = []; + for (const cell of row) { + ret.push(this.get_cell_value(cell, this.get_data_type(cell))); + } + return ret; + } } \ No newline at end of file