Skip to content

Commit 99c199c

Browse files
authored
Merge pull request #1568 from EPPlusSoftware/bug/issue1566
Fixes issue 1566
2 parents 867b951 + 4ff1abc commit 99c199c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/EPPlus/FormulaParsing/DependencyChain/RpnFormulaExecution.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private static object AddChainForFormula(RpnOptimizedDependencyChain depChain, R
474474
if (depChain.processedCells.Contains(ExcelCellBase.GetCellId(ws?.IndexInList??ushort.MaxValue, address.FromRow, address.FromCol)) == false)
475475
{
476476
rd?.Merge(address.FromRow, address.FromCol);
477-
if (ws._formulas.Exists(address.FromRow, address.FromCol, ref v))
477+
if (ws._formulas.Exists(address.FromRow, address.FromCol, ref v) && v != null)
478478
{
479479
depChain._formulaStack.Push(f);
480480
GetFormula(depChain, ws, address.FromRow, address.FromCol, v, ref f);

src/EPPlusTest/Issues/FormulaCalculationIssues.cs

+27-1
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,31 @@ public void i1540()
419419
SaveAndCleanup(p);
420420
}
421421
}
422-
}
422+
[TestMethod]
423+
public void i1566()
424+
{
425+
using (var package = new ExcelPackage())
426+
{
427+
var ws = package.Workbook.Worksheets.Add("Sheet1");
428+
/*
429+
This reference to a custom function is a simulation of my use-case.
430+
It doesn't appear to matter what the formula is, it just has to be set to something
431+
ws.Cells["A3"].Formula = "1"; // this works just as well as "@SomeCustomVbaFunction(A1,A2)"
432+
*/
433+
ws.Cells["A3"].Formula = "@SomeCustomVbaFunction(A1,A2)";
434+
/*
435+
* clear the formulas so that EPPlus doesn't go looking for SomeCustomVbaFunction
436+
I have purposefully chosen not to implement this function as a class extending ExcelFunction
437+
*/
438+
ws.Cells["A3"].ClearFormulas();
439+
//ws.Cells["A3"].Formula = "0"; //This may be a workaround for now
440+
ws.Cells["A3"].Value = "2000";
441+
ws.Cells["A4"].Formula = "ROUNDUP(A3/1609.334,0)";
442+
443+
ws.Calculate();
444+
Assert.AreEqual(2D, ws.Cells["A4"].Value);
445+
446+
}
447+
}
448+
}
423449
}

0 commit comments

Comments
 (0)