From bb0c84ae3d5c8bc894a92b0048141848a9621ff2 Mon Sep 17 00:00:00 2001 From: Geequlim Date: Thu, 21 Jan 2021 16:40:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=90=E4=B8=AA=E8=A1=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=95=B0=E7=BB=84=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- excel-exporter.yaml | 2 ++ src/excel-exporter/TableParser.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/excel-exporter.yaml b/excel-exporter.yaml index 7ad7084..f0d19b0 100644 --- a/excel-exporter.yaml +++ b/excel-exporter.yaml @@ -1,5 +1,7 @@ parser: first_row_as_field_comment: true + constant_array_length: + - EffectSequence input: - 配置表.xlsx output: diff --git a/src/excel-exporter/TableParser.ts b/src/excel-exporter/TableParser.ts index 0bc9704..3ebc19a 100644 --- a/src/excel-exporter/TableParser.ts +++ b/src/excel-exporter/TableParser.ts @@ -14,8 +14,8 @@ type RawTableData = RawTableCell[][]; export interface ParserConfigs { /** 第一行作为注释 */ first_row_as_field_comment: boolean; - /** 固定数组长度 */ - constant_array_length: boolean; + /** 固定数组长度的表名称 */ + constant_array_length: string[]; } export enum DataType { @@ -74,7 +74,7 @@ export class TableParser { let tables: { [key: string]: TableData } = {}; for (const name in raw_tables) { console.log(colors.grey(`\t解析配置表 ${name}`)); - tables[name] = this.process_table(raw_tables[name]); + tables[name] = this.process_table(name, raw_tables[name]); } return tables; } @@ -104,7 +104,7 @@ export class TableParser { return xlsl.utils.encode_cell({c: cell.column, r: cell.row}); } - protected process_table(raw: RawTableData): TableData { + protected process_table(sheet_name: string, raw: RawTableData): TableData { const type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool, DataType.null]; let headers: ColumnDescription[] = []; @@ -163,11 +163,11 @@ export class TableParser { } values.push(row); } - return this.parse_values(headers, values); + return this.parse_values(sheet_name, headers, values); } - protected parse_values(raw_headers : ColumnDescription[], raw_values: RawTableData) { + protected parse_values(sheet_name: string, raw_headers : ColumnDescription[], raw_values: RawTableData) { type FiledInfo = { column: ColumnDescription, start: number, @@ -207,7 +207,7 @@ export class TableParser { let arr = []; for (const idx of filed.indexes) { const cell = raw_row[idx]; - if (cell || this.configs.constant_array_length) { + if (cell || (Array.isArray(this.configs.constant_array_length) && this.configs.constant_array_length.includes(sheet_name))) { arr.push(this.get_cell_value(cell, filed.column.type)); } }