Skip to content

Commit

Permalink
Merge pull request #45 from Marketparts/44-empty-column-in-header
Browse files Browse the repository at this point in the history
Add last column to header array when value is empty
  • Loading branch information
jansivans authored Apr 8, 2022
2 parents 7fc530b + e7bf115 commit eb7e4c5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getFilledHeader(arr: any[], header: any[]) {
return header;
}
const filledHeader = [];
for (let i = 0; i < arr.length; i++) {
for (let i = 0; i < Math.max(arr.length, header.length); i++) {
filledHeader.push(
header[i] ? header[i] : `[${numbersToLetter(i + 1)}]`
);
Expand Down
39 changes: 37 additions & 2 deletions tests/__snapshots__/xlsx-stream.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,9 @@ Array [
"column1",
"column2",
"column3",
"column4",
],
"processedSheetSize": 1246,
"processedSheetSize": 2343,
"raw": Object {
"arr": Array [
"hello",
Expand All @@ -1358,7 +1359,41 @@ Array [
"column3": 123.123,
},
},
"totalSheetSize": 1246,
"totalSheetSize": 2343,
},
Object {
"formatted": Object {
"arr": Array [
undefined,
"world",
undefined,
456,
],
"obj": Object {
"column2": "world",
"column4": 456,
},
},
"header": Array [
"column1",
"column2",
"column3",
"column4",
],
"processedSheetSize": 2343,
"raw": Object {
"arr": Array [
undefined,
"world",
undefined,
456,
],
"obj": Object {
"column2": "world",
"column4": 456,
},
},
"totalSheetSize": 2343,
},
]
`;
Expand Down
Binary file modified tests/assets/with-header.xlsx
Binary file not shown.

0 comments on commit eb7e4c5

Please sign in to comment.