diff --git a/calc.go b/calc.go index 8777bb9413..19fbf97dc5 100644 --- a/calc.go +++ b/calc.go @@ -1626,7 +1626,10 @@ func (f *File) cellResolver(ctx *calcContext, sheet, cell string) (formulaArg, e if ctx.iterations[ref] <= f.options.MaxCalcIterations { ctx.iterations[ref]++ ctx.mu.Unlock() - arg, _ = f.calcCellValue(ctx, sheet, cell) + arg, err = f.calcCellValue(ctx, sheet, cell) + if err != nil && err.Error() != "#N/A" { + return arg, err + } ctx.iterationsCache[ref] = arg return arg, nil } diff --git a/cell_test.go b/cell_test.go index e64e46423b..d7fffa5fe2 100644 --- a/cell_test.go +++ b/cell_test.go @@ -1126,3 +1126,14 @@ func TestSharedStringsError(t *testing.T) { func TestSIString(t *testing.T) { assert.Empty(t, xlsxSI{}.String()) } + +func TestFormulaRecursionErr(t *testing.T) { + f, err := OpenFile(filepath.Join("test", "FormulaRecursionErr.xlsx"), Options{UnzipXMLSizeLimit: 128}) + assert.NoError(t, err) + _, err = f.CalcCellValue("Sheet1", "C1") + assert.Error(t, err) + _, err = f.CalcCellValue("Sheet1", "D1") + assert.Error(t, err) + err = f.Close() + assert.NoError(t, err) +} diff --git a/test/FormulaRecursionErr.xlsx b/test/FormulaRecursionErr.xlsx new file mode 100644 index 0000000000..0d3e1a108a Binary files /dev/null and b/test/FormulaRecursionErr.xlsx differ