Skip to content

Commit

Permalink
Fix getWorksheetRowObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Dec 20, 2024
1 parent d9f50ed commit a763c3b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/src/utils/xlsx-utils/worksheet-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ export const getWorksheetRowObjects = (worksheet: xlsx.WorkSheet): Record<symbol
let rowHasValues = false;

for (let j = 0; j <= originalRange.e.c; j++) {
// Always add the header (key) to the row object
rowObject[headers[j]] = undefined;

const cellAddress = { c: j, r: i };
const cellRef = xlsx.utils.encode_cell(cellAddress);
const cell = worksheet[cellRef];
Expand All @@ -213,14 +216,17 @@ export const getWorksheetRowObjects = (worksheet: xlsx.WorkSheet): Record<symbol
continue;
}

// Set the cell value for the header, if the cell exists
rowObject[headers[j]] = trimCellWhitespace(replaceCellDates(cell)).v;

// If at least one cell has a value, then the row is not empty
rowHasValues = true;
}

rowObject[RowIndex] = i;

if (rowHasValues) {
// Add the row object to the array if it has at least one non-empty cell
rowObjectsArray.push(rowObject);
}
}
Expand Down

0 comments on commit a763c3b

Please sign in to comment.