summaryrefslogtreecommitdiff
path: root/components/form-data/import-excel-form.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'components/form-data/import-excel-form.tsx')
-rw-r--r--components/form-data/import-excel-form.tsx34
1 files changed, 33 insertions, 1 deletions
diff --git a/components/form-data/import-excel-form.tsx b/components/form-data/import-excel-form.tsx
index fd9adc1c..d425a909 100644
--- a/components/form-data/import-excel-form.tsx
+++ b/components/form-data/import-excel-form.tsx
@@ -49,8 +49,14 @@ export async function importExcelData({
try {
if (onPendingChange) onPendingChange(true);
- // Get existing tag numbers
+ // Get existing tag numbers and create a map for quick lookup
const existingTagNumbers = new Set(tableData.map((d) => d.TAG_NO));
+ const existingDataMap = new Map<string, GenericData>();
+ tableData.forEach(item => {
+ if (item.TAG_NO) {
+ existingDataMap.set(item.TAG_NO, item);
+ }
+ });
const workbook = new ExcelJS.Workbook();
// const arrayBuffer = await file.arrayBuffer();
@@ -130,12 +136,38 @@ export async function importExcelData({
let errorMessage = "";
const rowObj: Record<string, any> = {};
+
+ // Get the TAG_NO first to identify existing data
+ const tagNoColIndex = keyToIndexMap.get("TAG_NO");
+ const tagNo = tagNoColIndex ? String(rowValues[tagNoColIndex] ?? "").trim() : "";
+ const existingRowData = existingDataMap.get(tagNo);
// Process each column
columnsJSON.forEach((col) => {
const colIndex = keyToIndexMap.get(col.key);
if (colIndex === undefined) return;
+ // Check if this column should be ignored (col.shi === true)
+ if (col.shi === true) {
+ // Use existing value instead of Excel value
+ if (existingRowData && existingRowData[col.key] !== undefined) {
+ rowObj[col.key] = existingRowData[col.key];
+ } else {
+ // If no existing data, use appropriate default
+ switch (col.type) {
+ case "NUMBER":
+ rowObj[col.key] = null;
+ break;
+ case "STRING":
+ case "LIST":
+ default:
+ rowObj[col.key] = "";
+ break;
+ }
+ }
+ return; // Skip processing Excel value for this column
+ }
+
const cellValue = rowValues[colIndex] ?? "";
let stringVal = String(cellValue).trim();