Skip to content

Commit d8904d0

Browse files
committed
Respect header row order when resolving conflicts
1 parent 77159f0 commit d8904d0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/xlsx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export class ExcelWorkbook {
1616

1717
function extract(sheet, {range, headers}) {
1818
let [[c0, r0], [c1, r1]] = parseRange(range, sheet);
19-
const headerRow = headers && sheet._rows[r0++];
2019
const seen = new Set();
2120
const names = [];
21+
const headerRow = headers && sheet._rows[r0++];
2222
function name(n) {
2323
if (!names[n]) {
2424
let name = (headerRow ? valueOf(headerRow._cells[n]) : AA(n)) || AA(n);
@@ -27,6 +27,7 @@ function extract(sheet, {range, headers}) {
2727
}
2828
return names[n];
2929
}
30+
if (headerRow) for (let c = c0; c <= c1; c++) name(c);
3031

3132
const output = new Array(r1 - r0 + 1).fill({});
3233
for (let r = r0; r <= r1; r++) {

test/xlsx-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ test("FileAttachment.xlsx reads sheets with headers", (t) => {
6464
const workbook = new ExcelWorkbook(
6565
mockWorkbook({
6666
Sheet1: [
67-
["one", "one", "one", "two"],
68-
[1, null, 3, 4],
69-
[5, 6, 7, 8],
67+
[null, "one", "one", "two", "A"],
68+
[ 1, null, 3, 4, 5],
69+
[ 6, 7, 8, 9, 10],
7070
],
7171
})
7272
);
7373
t.same(workbook.sheet(0, {headers: true}), [
74-
{one: 1, one_: 3, two: 4},
75-
{one: 5, one__: 6, one_: 7, two: 8},
74+
{A: 1, one_: 3, two: 4, A_: 5},
75+
{A: 6, one: 7, one_: 8, two: 9, A_: 10},
7676
]);
7777
t.end();
7878
});

0 commit comments

Comments
 (0)