|
|
|
@ -18,9 +18,7 @@ const excelTypeToUidt: Record<string, UITypes> = {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default class ExcelTemplateAdapter extends TemplateGenerator { |
|
|
|
|
config: { |
|
|
|
|
maxRowsToParse: number |
|
|
|
|
} & Record<string, any> |
|
|
|
|
config: Record<string, any> |
|
|
|
|
|
|
|
|
|
excelData: any |
|
|
|
|
|
|
|
|
@ -36,17 +34,11 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
|
|
|
|
|
constructor(data = {}, parserConfig = {}) { |
|
|
|
|
super() |
|
|
|
|
this.config = { |
|
|
|
|
maxRowsToParse: 500, |
|
|
|
|
...parserConfig, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.config = parserConfig |
|
|
|
|
this.excelData = data |
|
|
|
|
|
|
|
|
|
this.project = { |
|
|
|
|
tables: [], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.xlsx = {} as any |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -79,7 +71,6 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
tableNamePrefixRef[tn] = 0 |
|
|
|
|
|
|
|
|
|
const table = { table_name: tn, ref_table_name: tn, columns: [] as any[] } |
|
|
|
|
this.data[tn] = [] |
|
|
|
|
const ws: any = this.wb.Sheets[sheet] |
|
|
|
|
const range = this.xlsx.utils.decode_range(ws['!ref']) |
|
|
|
|
let rows: any = this.xlsx.utils.sheet_to_json(ws, { header: 1, blankrows: false, defval: null }) |
|
|
|
@ -207,7 +198,10 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
} |
|
|
|
|
table.columns.push(column) |
|
|
|
|
} |
|
|
|
|
this.project.tables.push(table) |
|
|
|
|
|
|
|
|
|
this.data[tn] = [] |
|
|
|
|
if (this.config.importData) { |
|
|
|
|
let rowIndex = 0 |
|
|
|
|
for (const row of rows.slice(1)) { |
|
|
|
|
const rowData: Record<string, any> = {} |
|
|
|
@ -239,7 +233,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
|
|
|
|
|
this.data[tn].push(rowData) |
|
|
|
|
rowIndex++ |
|
|
|
|
} |
|
|
|
|
this.project.tables.push(table) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resolve(true) |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|