@mixd-id/web-scaffold 0.1.240411104 → 0.1.240411105
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/package.json +1 -1
- package/src/utils/importer.js +15 -9
package/package.json
CHANGED
package/src/utils/importer.js
CHANGED
|
@@ -32,6 +32,10 @@ const getCellText = (cell, image) => {
|
|
|
32
32
|
|
|
33
33
|
const cellKey = (row, col) => row + ',' + col
|
|
34
34
|
|
|
35
|
+
// Header labels often carry stray padding in the source file ("TEKS PROGRAM "),
|
|
36
|
+
// normalise them so the column mapping does not depend on it
|
|
37
|
+
const columnName = (value) => `${value ?? ''}`.trim()
|
|
38
|
+
|
|
35
39
|
// Maps the cell an image is anchored on to its media entry ({ buffer, extension, name }).
|
|
36
40
|
// Only the top left anchor counts, an image spilling over its neighbours stays on one cell.
|
|
37
41
|
const getWorksheetImages = (workbook, worksheet) => {
|
|
@@ -118,10 +122,10 @@ const analyseRequest = async(req) => {
|
|
|
118
122
|
header.eachCell((cell) => {
|
|
119
123
|
if(cell.isMerged){
|
|
120
124
|
const sub = worksheet.getCell(cell.address.replace(/\d/g, '') + '2').value
|
|
121
|
-
columns.push(cell.value + '>' + sub)
|
|
125
|
+
columns.push(columnName(cell.value) + '>' + columnName(sub))
|
|
122
126
|
}
|
|
123
127
|
else{
|
|
124
|
-
columns.push(cell.value)
|
|
128
|
+
columns.push(columnName(cell.value))
|
|
125
129
|
}
|
|
126
130
|
})
|
|
127
131
|
|
|
@@ -190,11 +194,11 @@ const importRequest = async(req) => {
|
|
|
190
194
|
header.eachCell((cell, index) => {
|
|
191
195
|
if(cell.isMerged){
|
|
192
196
|
const sub = worksheet.getCell(cell.address.replace(/\d/g, '') + '2').value
|
|
193
|
-
columnAddress[cell.value + '>' + sub] = index
|
|
197
|
+
columnAddress[columnName(cell.value) + '>' + columnName(sub)] = index
|
|
194
198
|
rowStart = 3
|
|
195
199
|
}
|
|
196
200
|
else{
|
|
197
|
-
columnAddress[cell.value] = index
|
|
201
|
+
columnAddress[columnName(cell.value)] = index
|
|
198
202
|
}
|
|
199
203
|
})
|
|
200
204
|
|
|
@@ -227,8 +231,9 @@ const importRequest = async(req) => {
|
|
|
227
231
|
let isItalic = false
|
|
228
232
|
for(let idx in keys){
|
|
229
233
|
const key = keys[idx]
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
const address = columnAddress[columnName(key.value)]
|
|
235
|
+
if(key.value && address){
|
|
236
|
+
const cell = row.getCell(address)
|
|
232
237
|
if(cell.font && cell.font.italic){
|
|
233
238
|
isItalic = true
|
|
234
239
|
break
|
|
@@ -243,9 +248,10 @@ const importRequest = async(req) => {
|
|
|
243
248
|
if(keys){
|
|
244
249
|
for(let idx in keys){
|
|
245
250
|
const key = keys[idx]
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
const address = columnAddress[columnName(key.value)]
|
|
252
|
+
if(key.value && address){
|
|
253
|
+
const cell = row.getCell(address)
|
|
254
|
+
obj[key.key] = getCellText(cell, cellImages.get(cellKey(index, address)))
|
|
249
255
|
}
|
|
250
256
|
}
|
|
251
257
|
}
|