@things-factory/import-ui-excel 4.3.695 → 4.3.700
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/bootstrap.js +30 -8
- package/package.json +2 -2
package/client/bootstrap.js
CHANGED
|
@@ -3,6 +3,26 @@ import { store } from '@things-factory/shell'
|
|
|
3
3
|
import * as XLSX from '!xlsx'
|
|
4
4
|
import Excel from '!exceljs'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Normalize cell value - handles ExcelJS hyperlink objects and other object types
|
|
8
|
+
* @param {any} cellVal - The cell value from ExcelJS
|
|
9
|
+
* @return {any} - Normalized value (string for hyperlinks, original value otherwise)
|
|
10
|
+
*/
|
|
11
|
+
function normalizeCellValue(cellVal) {
|
|
12
|
+
// Handle ExcelJS hyperlink objects (e.g., { text: 'email@example.com', hyperlink: 'mailto:...' })
|
|
13
|
+
if (cellVal && typeof cellVal === 'object' && !Array.isArray(cellVal)) {
|
|
14
|
+
if (cellVal.text !== undefined) {
|
|
15
|
+
return cellVal.text
|
|
16
|
+
}
|
|
17
|
+
// For other object types, try to extract a meaningful value
|
|
18
|
+
if (cellVal.toString && cellVal.toString() !== '[object Object]') {
|
|
19
|
+
return cellVal.toString()
|
|
20
|
+
}
|
|
21
|
+
return ''
|
|
22
|
+
}
|
|
23
|
+
return cellVal
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
/**
|
|
7
27
|
* Convert Excel to Object
|
|
8
28
|
* @param {ArrayBufferTypes} params - Array Buffer of the excel file.
|
|
@@ -14,7 +34,8 @@ async function excelToObj(params) {
|
|
|
14
34
|
|
|
15
35
|
let ws = workbook.getWorksheet(1)
|
|
16
36
|
ws._rows[0]._cells.map((cell, index) => {
|
|
17
|
-
|
|
37
|
+
const cellValue = normalizeCellValue(cell.value)
|
|
38
|
+
ws._columns[index]._key = cell.name || (typeof cellValue === 'string' ? cellValue.toLowerCase() : '')
|
|
18
39
|
})
|
|
19
40
|
|
|
20
41
|
//Fetch supporting data and place it under 'extraData' object.
|
|
@@ -53,7 +74,7 @@ async function excelToObj(params) {
|
|
|
53
74
|
columnType = ws.dataValidations?.model[currentCell._address]?.type
|
|
54
75
|
}
|
|
55
76
|
|
|
56
|
-
let cellVal = currentCell ? currentCell.value : ''
|
|
77
|
+
let cellVal = currentCell ? normalizeCellValue(currentCell.value) : ''
|
|
57
78
|
|
|
58
79
|
let arrColumnKeys = ws._columns[columncount].key?.split('.')
|
|
59
80
|
if (arrColumnKeys.length > 1) {
|
|
@@ -70,23 +91,24 @@ async function excelToObj(params) {
|
|
|
70
91
|
prev[e] = cellVal ? parseFloat(cellVal) : 0
|
|
71
92
|
break
|
|
72
93
|
default:
|
|
73
|
-
prev[e] = cellVal ? cellVal.toString() : null
|
|
94
|
+
prev[e] = cellVal !== null && cellVal !== undefined ? cellVal.toString() : null
|
|
74
95
|
break
|
|
75
96
|
}
|
|
76
97
|
}
|
|
77
98
|
return prev[e]
|
|
78
99
|
}, objRow)
|
|
79
100
|
} else {
|
|
80
|
-
|
|
81
|
-
(ws._rows[0]._cells[columncount].value
|
|
82
|
-
|
|
83
|
-
) {
|
|
101
|
+
const headerCellValue = ws._rows[0]._cells[columncount]
|
|
102
|
+
? normalizeCellValue(ws._rows[0]._cells[columncount].value)
|
|
103
|
+
: ''
|
|
104
|
+
if ((headerCellValue === 'id' && cellVal !== '') || headerCellValue !== 'id') {
|
|
84
105
|
switch (columnType) {
|
|
85
106
|
case 'decimal':
|
|
86
107
|
objRow[ws._columns[columncount].key] = cellVal ? parseFloat(cellVal) : 0
|
|
87
108
|
break
|
|
88
109
|
default:
|
|
89
|
-
objRow[ws._columns[columncount].key] =
|
|
110
|
+
objRow[ws._columns[columncount].key] =
|
|
111
|
+
cellVal !== null && cellVal !== undefined ? cellVal.toString() : null
|
|
90
112
|
break
|
|
91
113
|
}
|
|
92
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/import-ui-excel",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.700",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"@things-factory/layout-base": "^4.3.695",
|
|
28
28
|
"xlsx": "^0.16.8"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "f1b712fc8f3a7b7b5136204e4c4fd6bfad0e766e"
|
|
31
31
|
}
|