diff --git a/package-lock.json b/package-lock.json index 13c46ad..ff56c99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "xlstream", - "version": "2.5.0", + "version": "2.5.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.5.0", + "version": "2.5.1", "license": "MIT", "dependencies": { "deep-rename-keys": "^0.2.1", diff --git a/src/index.ts b/src/index.ts index 9d4d31f..ad16619 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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)}]` ); diff --git a/tests/__snapshots__/xlsx-stream.spec.ts.snap b/tests/__snapshots__/xlsx-stream.spec.ts.snap index a0c0ef5..0767f03 100644 --- a/tests/__snapshots__/xlsx-stream.spec.ts.snap +++ b/tests/__snapshots__/xlsx-stream.spec.ts.snap @@ -1345,8 +1345,9 @@ Array [ "column1", "column2", "column3", + "column4", ], - "processedSheetSize": 1246, + "processedSheetSize": 2343, "raw": Object { "arr": Array [ "hello", @@ -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, }, ] `; diff --git a/tests/assets/with-header.xlsx b/tests/assets/with-header.xlsx index b509c27..19f1bb8 100644 Binary files a/tests/assets/with-header.xlsx and b/tests/assets/with-header.xlsx differ