Browse Source

fix(nc-gui): take raw data if autoSelectFieldType is true

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
f308f41bb3
  1. 16
      packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts

16
packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts

@ -88,6 +88,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
}) })
return new Date(parsed.y, parsed.m, parsed.d, parsed.H, parsed.M, parsed.S) return new Date(parsed.y, parsed.m, parsed.d, parsed.H, parsed.M, parsed.S)
} }
// fix imported date // fix imported date
rows = rows.map((r: any) => rows = rows.map((r: any) =>
r.map((v: any) => { r.map((v: any) => {
@ -209,6 +210,15 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
for (const row of rows.slice(1)) { for (const row of rows.slice(1)) {
const rowData: Record<string, any> = {} const rowData: Record<string, any> = {}
for (let i = 0; i < table.columns.length; i++) { for (let i = 0; i < table.columns.length; i++) {
if (!this.config.autoSelectFieldType) {
// take raw data instead of data parsed by xlsx
const cellId = this.xlsx.utils.encode_cell({
c: range.s.c + i,
r: rowIndex + columnNameRowExist,
})
const cellObj = ws[cellId]
rowData[table.columns[i].column_name] = cellObj.w
} else {
if (table.columns[i].uidt === UITypes.Checkbox) { if (table.columns[i].uidt === UITypes.Checkbox) {
rowData[table.columns[i].column_name] = getCheckboxValue(row[i]) rowData[table.columns[i].column_name] = getCheckboxValue(row[i])
} else if (table.columns[i].uidt === UITypes.Currency) { } else if (table.columns[i].uidt === UITypes.Currency) {
@ -218,7 +228,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
}) })
const cellObj = ws[cellId] const cellObj = ws[cellId]
rowData[table.columns[i].column_name] = (cellObj && cellObj.w && cellObj.w.replace(/[^\d.]+/g, '')) || row[i] rowData[table.columns[i].column_name] =
(cellObj && cellObj.w && cellObj.w.replace(/[^\d.]+/g, '')) || row[i]
} else if (table.columns[i].uidt === UITypes.SingleSelect || table.columns[i].uidt === UITypes.MultiSelect) { } else if (table.columns[i].uidt === UITypes.SingleSelect || table.columns[i].uidt === UITypes.MultiSelect) {
rowData[table.columns[i].column_name] = (row[i] || '').toString().trim() || null rowData[table.columns[i].column_name] = (row[i] || '').toString().trim() || null
} else if (table.columns[i].uidt === UITypes.Date) { } else if (table.columns[i].uidt === UITypes.Date) {
@ -229,10 +240,11 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
const cellObj = ws[cellId] const cellObj = ws[cellId]
rowData[table.columns[i].column_name] = (cellObj && cellObj.w) || row[i] rowData[table.columns[i].column_name] = (cellObj && cellObj.w) || row[i]
} else { } else {
// toto: do parsing if necessary based on type // TODO: do parsing if necessary based on type
rowData[table.columns[i].column_name] = row[i] rowData[table.columns[i].column_name] = row[i]
} }
} }
}
this.data[tn].push(rowData) this.data[tn].push(rowData)
rowIndex++ rowIndex++
} }

Loading…
Cancel
Save