From c3d7008077ff65a1f905e516e997f8fe03ab56df Mon Sep 17 00:00:00 2001 From: catamphetamine Date: Sat, 12 Feb 2022 19:09:27 +0300 Subject: [PATCH] . --- package-lock.json | 2 +- package.json | 2 +- source/read/getData.js | 7 +++++-- source/read/parseDimensions.js | 9 +++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e198e22..d79afb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "read-excel-file", - "version": "5.2.27", + "version": "5.2.28", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9ddd600..78bafc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "read-excel-file", - "version": "5.2.27", + "version": "5.2.28", "description": "Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.", "module": "index.js", "sideEffects": false, diff --git a/source/read/getData.js b/source/read/getData.js index 6e6cd64..8653f84 100644 --- a/source/read/getData.js +++ b/source/read/getData.js @@ -32,7 +32,7 @@ export default function getData(sheet, options) { i++ } - // Fill in spreadsheet data structure. + // Fill in spreadsheet `data`. // (this code implies that `cells` aren't necessarily sorted by row and column: // maybe that's not correct, this piece code was initially copy-pasted // from some other library that used `XPath`) @@ -43,7 +43,10 @@ export default function getData(sheet, options) { // const columnIndex = cell.column - leftTop.column const rowIndex = cell.row - 1 const columnIndex = cell.column - 1 - data[rowIndex][columnIndex] = cell.value + // Ignore the data in the cell if it's outside of the spreadsheet's "dimensions". + if (columnIndex < colsCount && rowIndex < rowsCount) { + data[rowIndex][columnIndex] = cell.value + } } // Fill in the row map. diff --git a/source/read/parseDimensions.js b/source/read/parseDimensions.js index bd37ec3..2de8a61 100644 --- a/source/read/parseDimensions.js +++ b/source/read/parseDimensions.js @@ -15,8 +15,13 @@ export default function parseDimensions(sheet) { row, column })) - // When there's only a single cell on a sheet - // there can sometimes be just "A1" for the dimensions string. + // Sometimes there can be just a single cell as a spreadsheet's "dimensions". + // For example, the default "dimensions" in Apache POI library is "A1", + // meaning that only the first cell in the spreadsheet is used. + // + // A quote from Apache POI library: + // "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')." + // if (dimensions.length === 1) { dimensions = [dimensions[0], dimensions[0]] }