Skip to content

Commit 42ad922

Browse files
Avoid looking up absent cells in rangeResolver
1 parent 91d36cc commit 42ad922

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

calc.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,16 +1690,31 @@ func (f *File) rangeResolver(ctx *calcContext, cellRefs, cellRanges *list.List)
16901690
// extract value from ranges
16911691
if cellRanges.Len() > 0 {
16921692
arg.Type = ArgMatrix
1693+
1694+
var ws *xlsxWorksheet
1695+
ws, err = f.workSheetReader(sheet)
1696+
if err != nil {
1697+
return
1698+
}
1699+
16931700
for row := valueRange[0]; row <= valueRange[1]; row++ {
1701+
colMax := 0
1702+
if row <= len(ws.SheetData.Row) {
1703+
rowData := &ws.SheetData.Row[row-1]
1704+
colMax = min(valueRange[3], len(rowData.C))
1705+
}
1706+
16941707
var matrixRow []formulaArg
16951708
for col := valueRange[2]; col <= valueRange[3]; col++ {
1696-
var cell string
1697-
var value formulaArg
1698-
if cell, err = CoordinatesToCellName(col, row); err != nil {
1699-
return
1700-
}
1701-
if value, err = f.cellResolver(ctx, sheet, cell); err != nil {
1702-
return
1709+
value := newEmptyFormulaArg()
1710+
if col <= colMax {
1711+
var cell string
1712+
if cell, err = CoordinatesToCellName(col, row); err != nil {
1713+
return
1714+
}
1715+
if value, err = f.cellResolver(ctx, sheet, cell); err != nil {
1716+
return
1717+
}
17031718
}
17041719
matrixRow = append(matrixRow, value)
17051720
}

calc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ func TestCalcCellValue(t *testing.T) {
19971997
// VLOOKUP
19981998
"=VLOOKUP(D2,D:D,1,FALSE)": "Jan",
19991999
"=VLOOKUP(D2,D1:D10,1)": "Jan",
2000-
"=VLOOKUP(D2,D1:D11,1)": "Feb",
2000+
"=VLOOKUP(D2,D3:D11,1)": "Feb",
20012001
"=VLOOKUP(D2,D1:D10,1,FALSE)": "Jan",
20022002
"=VLOOKUP(INT(36693),F2:F2,1,FALSE)": "36693",
20032003
"=VLOOKUP(INT(F2),F3:F9,1)": "32080",

0 commit comments

Comments
 (0)