Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/officecli/Core/Formula/FormulaEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ private void RestoreBindings(Dictionary<string, FormulaResult> snapshot)

// ==================== Cell & Range Resolution ====================

// External-workbook reference marker in a stored formula (the "[1]" in
// "[1]Sheet!A1"); such refs can't be resolved without the linked file.
private static readonly Regex ExternalRefRe = new(@"\[\d+\]", RegexOptions.Compiled);

internal FormulaResult? ResolveCellResult(string cellRef)
{
cellRef = StripDollar(cellRef).ToUpperInvariant();
Expand Down Expand Up @@ -1250,7 +1254,12 @@ private void RestoreBindings(Dictionary<string, FormulaResult> snapshot)
{
var circularBefore = _session.CircularHits;
var evaluated = EvaluateFormula(ModernFunctionQualifier.Unqualify(cell.CellFormula.Text));
if (evaluated != null)
// An external-workbook reference (=[1]Sheet!A1) can't be resolved without
// the linked file and surfaces as #REF!. Excel keeps the last cached <v>
// for such cells, so fall through to it rather than poisoning every
// dependent total with #REF!. Genuine errors (no external link) still propagate.
if (evaluated != null
&& !(evaluated.IsError && ExternalRefRe.IsMatch(cell.CellFormula.Text)))
{
// Memoize only clean results: no live bindings (see lookup
// guard above) and no circular fallback during this
Expand Down