|
@@ -86,11 +86,13 @@ export class ExcelReaderService {
|
|
|
// Map cell values based on field configuration
|
|
// Map cell values based on field configuration
|
|
|
for (const field of section.fields || []) {
|
|
for (const field of section.fields || []) {
|
|
|
try {
|
|
try {
|
|
|
- const cellAddress = this.parseCellAddress(field.cellPosition);
|
|
|
|
|
|
|
+ const cellAddress = this.parseCellAddress(field.cellPosition, rowNum);
|
|
|
const cellValue = row[cellAddress.col - 1]; // Convert to 0-based index
|
|
const cellValue = row[cellAddress.col - 1]; // Convert to 0-based index
|
|
|
|
|
|
|
|
if (cellValue !== null && cellValue !== undefined && cellValue !== '') {
|
|
if (cellValue !== null && cellValue !== undefined && cellValue !== '') {
|
|
|
const value = this.convertCellValue(
|
|
const value = this.convertCellValue(
|
|
|
|
|
+ field.dataType,
|
|
|
|
|
+ field.dataTypeFormat,
|
|
|
cellValue,
|
|
cellValue,
|
|
|
field.parsedType || FieldTypeEnum.String
|
|
field.parsedType || FieldTypeEnum.String
|
|
|
);
|
|
);
|
|
@@ -99,8 +101,12 @@ export class ExcelReaderService {
|
|
|
const columnName = field.importTableColumnName;
|
|
const columnName = field.importTableColumnName;
|
|
|
rowData[columnName] = value;
|
|
rowData[columnName] = value;
|
|
|
}
|
|
}
|
|
|
- } catch {
|
|
|
|
|
- // Error processing field, skip this field
|
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.log(`Error processing field ${field.name} at row ${rowNum}`, {
|
|
|
|
|
+ error: error instanceof Error ? error.message : String(error),
|
|
|
|
|
+ field,
|
|
|
|
|
+ rowNum
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -140,10 +146,14 @@ export class ExcelReaderService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private parseCellAddress(cellPosition: string): { row: number; col: number } {
|
|
|
|
|
- const match = cellPosition.match(/([A-Z]+)(\d+)/);
|
|
|
|
|
|
|
+ private parseCellAddress(cellPosition: string, rowNumber: number): { row: number; col: number } {
|
|
|
|
|
+ let match = cellPosition.match(/([A-Z]+)(\d+)/);
|
|
|
if (!match) {
|
|
if (!match) {
|
|
|
- return { row: 1, col: 1 };
|
|
|
|
|
|
|
+ const appendedCellPosition = `${cellPosition}${rowNumber}`;
|
|
|
|
|
+ match = appendedCellPosition.match(/([A-Z]+)(\d+)/);
|
|
|
|
|
+ if (!match) {
|
|
|
|
|
+ return { row: 1, col: 1 };
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const col = match[1].charCodeAt(0) - 'A'.charCodeAt(0) + 1;
|
|
const col = match[1].charCodeAt(0) - 'A'.charCodeAt(0) + 1;
|
|
@@ -211,12 +221,15 @@ export class ExcelReaderService {
|
|
|
return mappedType;
|
|
return mappedType;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private convertCellValue(value: any, fieldType: FieldTypeEnum): any {
|
|
|
|
|
|
|
+ private convertCellValue(dataType: string, dataTypeFormat: string | undefined, value: any, fieldType: FieldTypeEnum): any {
|
|
|
if (value === null || value === undefined) {
|
|
if (value === null || value === undefined) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const convertedValue = (() => {
|
|
const convertedValue = (() => {
|
|
|
|
|
+ if (dataType === "DATE" && (typeof value === 'number' || value instanceof Date))
|
|
|
|
|
+ return XLSX.SSF.format(dataTypeFormat || 'yyyy-mm-dd', value);
|
|
|
|
|
+
|
|
|
switch (fieldType) {
|
|
switch (fieldType) {
|
|
|
case FieldTypeEnum.Time:
|
|
case FieldTypeEnum.Time:
|
|
|
if (typeof value === 'number') {
|
|
if (typeof value === 'number') {
|