Skip to content

Commit c3d7008

Browse files
.
1 parent 134b4b1 commit c3d7008

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "read-excel-file",
3-
"version": "5.2.27",
3+
"version": "5.2.28",
44
"description": "Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.",
55
"module": "index.js",
66
"sideEffects": false,

source/read/getData.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function getData(sheet, options) {
3232
i++
3333
}
3434

35-
// Fill in spreadsheet data structure.
35+
// Fill in spreadsheet `data`.
3636
// (this code implies that `cells` aren't necessarily sorted by row and column:
3737
// maybe that's not correct, this piece code was initially copy-pasted
3838
// from some other library that used `XPath`)
@@ -43,7 +43,10 @@ export default function getData(sheet, options) {
4343
// const columnIndex = cell.column - leftTop.column
4444
const rowIndex = cell.row - 1
4545
const columnIndex = cell.column - 1
46-
data[rowIndex][columnIndex] = cell.value
46+
// Ignore the data in the cell if it's outside of the spreadsheet's "dimensions".
47+
if (columnIndex < colsCount && rowIndex < rowsCount) {
48+
data[rowIndex][columnIndex] = cell.value
49+
}
4750
}
4851

4952
// Fill in the row map.

source/read/parseDimensions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ export default function parseDimensions(sheet) {
1515
row,
1616
column
1717
}))
18-
// When there's only a single cell on a sheet
19-
// there can sometimes be just "A1" for the dimensions string.
18+
// Sometimes there can be just a single cell as a spreadsheet's "dimensions".
19+
// For example, the default "dimensions" in Apache POI library is "A1",
20+
// meaning that only the first cell in the spreadsheet is used.
21+
//
22+
// A quote from Apache POI library:
23+
// "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')."
24+
//
2025
if (dimensions.length === 1) {
2126
dimensions = [dimensions[0], dimensions[0]]
2227
}

0 commit comments

Comments
 (0)