Skip to content

Commit 2d1089a

Browse files
authored
Fixes issue #2265 (#2267)
1 parent c246dbc commit 2d1089a

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/EPPlus.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31912.275
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.0.11217.181 d18.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EPPlus", "EPPlus\EPPlus.csproj", "{219F673E-6115-4858-9E07-E33D24E795FE}"
77
EndProject

src/EPPlus/FormulaParsing/DependencyChain/RpnFormulaExecution.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private static CompileResult CalculateFormulaChain(RpnOptimizedDependencyChain d
410410
RangeHashset rd = AddOrGetRDFromWsIx(depChain, f._ws == null ? -1 : f._ws.IndexInList);
411411
object v = null;
412412
bool hasLogger = depChain._parsingContext.Parser.Logger != null;
413-
var followChain = options.FollowDependencyChain && depChainPos==-1;
413+
var followChain = options.FollowDependencyChain;
414414
if (depChainPos == -1)
415415
{
416416
rd?.Merge(f._row, f._column);
@@ -423,7 +423,7 @@ private static CompileResult CalculateFormulaChain(RpnOptimizedDependencyChain d
423423
var ws = f._ws;
424424
if (f._tokenIndex < f._tokens.Count)
425425
{
426-
addresses = ExecuteNextToken(depChain, f, followChain || depChain._formulaStack.Count>0);
426+
addresses = ExecuteNextToken(depChain, f, followChain);
427427
if (f._tokenIndex < f._tokens.Count)
428428
{
429429
if (addresses == null && f._expressions.ContainsKey(f._tokenIndex) && f._expressions[f._tokenIndex].ExpressionType == ExpressionType.NameValue)
@@ -807,7 +807,7 @@ private static void SetValueToWorkbook(RpnOptimizedDependencyChain depChain, Rpn
807807
}
808808
private static void RecalculateDirtyCells(SimpleAddress[] dirtyRange, RpnOptimizedDependencyChain depChain, RangeHashset rd, ExcelCalculationOption options)
809809
{
810-
if(depChain._isInRecalculateDirtyCells) return; //EPPlus will not recalculate dirty cells while recalculating other dirty cells to avoid stack overflow.
810+
if(depChain._isInRecalculateDirtyCells || options.FollowDependencyChain==false) return; //EPPlus will not recalculate dirty cells while recalculating other dirty cells to avoid stack overflow.
811811
var dirtyCells = dirtyRange.ToList();
812812
if (depChain.FormulaRangeReferences.ContainsKey(depChain._parsingContext.CurrentWorksheet.IndexInList))
813813
{
@@ -1055,6 +1055,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
10551055
{
10561056
FormulaRangeAddress[] addresses;
10571057
var s = f._expressionStack;
1058+
bool IsInRecalculateDirtyCells = depChain._isInRecalculateDirtyCells;
10581059
while (f._tokenIndex < f._tokens.Count)
10591060
{
10601061
if (f.HasLambdaToken(f._tokenIndex))
@@ -1150,7 +1151,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
11501151
f.LambdaSettings.LambdaArgsAdded.Push(++nLambdaArgsAdded);
11511152
}
11521153
}
1153-
if (localReturnAddress && returnAddresses && (f._funcStack.Count == 0 || ShouldIgnoreAddress(f._funcStack.Peek()) == false))
1154+
if (localReturnAddress && returnAddresses && (f._funcStack.Count == 0 || ShouldIgnoreAddress(f._funcStack.Peek()) == false) && IsInRecalculateDirtyCells == false)
11541155
{
11551156
if(f._tokenIndex + 1 < f._tokens.Count)
11561157
{
@@ -1178,12 +1179,12 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
11781179
var nameAddress = ne.GetAddress();
11791180
if (nameAddress == null)
11801181
{
1181-
if (returnAddresses && string.IsNullOrEmpty(ne._name?.Formula) == false)
1182+
if (returnAddresses && string.IsNullOrEmpty(ne._name?.Formula) == false && IsInRecalculateDirtyCells == false)
11821183
{
11831184
return null;
11841185
}
11851186
}
1186-
else if (returnAddresses && (f._funcStack.Count == 0 || ShouldIgnoreAddress(f._funcStack.Peek()) == false))
1187+
else if (returnAddresses && (f._funcStack.Count == 0 || ShouldIgnoreAddress(f._funcStack.Peek()) == false) && IsInRecalculateDirtyCells == false)
11871188
{
11881189
if (IsSingleAddress(f))
11891190
{
@@ -1252,7 +1253,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
12521253
f.IgnoreCaching = true;
12531254
}
12541255

1255-
if (PreExecFunc(depChain, f, funcExp))
1256+
if (PreExecFunc(depChain, f, funcExp) && returnAddresses)
12561257
{
12571258
f._currentFunction = funcExp;
12581259
f._tokenIndex--; //We should stay on this token when we continue on this formula.
@@ -1264,7 +1265,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
12641265
else
12651266
{
12661267
funcExp = f._currentFunction;
1267-
if (funcExp._dependencyAddresses.Count > 0)
1268+
if (funcExp._dependencyAddresses.Count > 0 && returnAddresses)
12681269
{
12691270
f._tokenIndex--; //We should stay on this token when we continue on this formula.
12701271
var a = funcExp._dependencyAddresses.ToArray();
@@ -1290,7 +1291,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
12901291
f.LambdaSettings.LambdaStackNumbers.Push(s.Count);
12911292
f.LambdaSettings.NumberOfLambdaVariables.Push(clc.NumberOfVariables);
12921293
}
1293-
if (r.Address != null)
1294+
if (r.Address != null && returnAddresses)
12941295
{
12951296
if ((f._funcStack.Count == 0 || ShouldIgnoreAddress(f._funcStack.Peek()) == false) && r.Address != null)
12961297
{
@@ -1382,7 +1383,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
13821383
}
13831384

13841385
f._tokenIndex++;
1385-
if (f._tokenIndex == f._tokens.Count)
1386+
if (f._tokenIndex == f._tokens.Count && returnAddresses)
13861387
{
13871388
if (s.Count > 0 && s.Peek().Status == ExpressionStatus.IsAddress)
13881389
{

0 commit comments

Comments
 (0)