Skip to content
1 change: 1 addition & 0 deletions src/EPPlus/FormulaParsing/DependencyChain/RpnFormula.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ internal LambdaExpressionStackPosition GetCurrentLambdaExpressionStackPosition()
internal int GetNumberOfLambdaVariables()
{
if (_lambdaSettings == null || _lambdaSettings.NumberOfLambdaVariables == null || _lambdaSettings.NumberOfLambdaVariables.Count == 0) return 0;
if (_lambdaSettings.CurrentLambdaExpressions.Peek().Expression.ArgumentCollectionStarted == false) return 0;
return _lambdaSettings.NumberOfLambdaVariables.Peek();
}

Expand Down
21 changes: 15 additions & 6 deletions src/EPPlus/FormulaParsing/DependencyChain/RpnFormulaExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,11 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
{
exp.Status |= ExpressionStatus.IsLambdaVariableDeclaration;
}

if (t.TokenType == TokenType.EtaReducedLambda)
{
((FunctionExpression)f._expressions[f._tokenIndex]).SetRpnFormula(f);
}

var cr = exp.Compile();
if (cr.DataType == DataType.LambdaTokens)
{
Expand All @@ -1140,7 +1144,11 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
{
s.Push(f._expressions[f._tokenIndex]);
}
else if (cr.DataType != DataType.LambdaVariableDeclaration && f.LambdaSettings.LambdaArgsAdded.Count > 0 && f.LambdaSettings.LambdaArgsAdded.Peek() < f.GetNumberOfLambdaVariables())
else if(
f._expressionStack.Peek() is LambdaCalculationExpression lce2 && lce2.ArgumentCollectionStarted &&
cr.DataType != DataType.LambdaVariableDeclaration
&& f.LambdaSettings.LambdaArgsAdded.Count > 0
&& f.LambdaSettings.LambdaArgsAdded.Peek() < f.GetNumberOfLambdaVariables())
{
leStackPos.Expression.SetVariable(f.LambdaSettings.LambdaArgsAdded.Peek(), cr.Result, cr.DataType, cr.Address);
var nLambdaArgsAdded = f.LambdaSettings.LambdaArgsAdded.Pop();
Expand All @@ -1155,10 +1163,7 @@ private static FormulaRangeAddress[] ExecuteNextToken(RpnOptimizedDependencyChai
{
s.Push(f._expressions[f._tokenIndex]);
}
if(t.TokenType == TokenType.EtaReducedLambda)
{
((FunctionExpression)f._expressions[f._tokenIndex]).SetRpnFormula(f);
}

break;
case TokenType.Negator:
s.Push(s.Pop().Negate());
Expand Down Expand Up @@ -1735,6 +1740,10 @@ private static IList<CompileResult> CompileFunctionArguments(RpnFormula f, Funct
{
si.Status |= ExpressionStatus.FunctionArgument;
}
if(si is FunctionExpression fe1)
{
fe1.SetRpnFormula(f);
}
var cr = si.Compile();
list.Insert(0, cr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public BuiltInFunctions()
// Reference and lookup
Functions["address"] = new Address();
Functions["areas"] = new Areas();
Functions["groupby"] = new GroupBy();
Functions["hlookup"] = new HLookup();
Functions["vlookup"] = new VLookup();
Functions["xlookup"] = new Xlookup();
Expand Down
27 changes: 23 additions & 4 deletions src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@
{

}

public virtual string Name

Check warning on line 132 in src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs

View workflow job for this annotation

GitHub Actions / CodeQL (csharp)

Missing XML comment for publicly visible type or member 'ExcelFunction.Name'

Check warning on line 132 in src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs

View workflow job for this annotation

GitHub Actions / CodeQL (csharp)

Missing XML comment for publicly visible type or member 'ExcelFunction.Name'

Check warning on line 132 in src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs

View workflow job for this annotation

GitHub Actions / CodeQL (csharp)

Missing XML comment for publicly visible type or member 'ExcelFunction.Name'

Check warning on line 132 in src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs

View workflow job for this annotation

GitHub Actions / CodeQL (csharp)

Missing XML comment for publicly visible type or member 'ExcelFunction.Name'

Check warning on line 132 in src/EPPlus/FormulaParsing/Excel/Functions/ExcelFunction.cs

View workflow job for this annotation

GitHub Actions / CodeQL (csharp)

Missing XML comment for publicly visible type or member 'ExcelFunction.Name'
{
get
{
return GetType().Name.ToUpper();
}
}
/// <summary>
/// Indicates that the function is an ErrorHandlingFunction.
/// </summary>
Expand Down Expand Up @@ -895,10 +903,21 @@
return true;
}
}
/// <summary>
/// Provides information about the functions parameters.
/// </summary>
public virtual ExcelFunctionParametersInfo ParametersInfo
/// <summary>
/// The function is allowed...
/// </summary>
public virtual bool IsAllowedAsLambdaWithMultipleArguments
{
get
{
return false;
}
}

/// <summary>
/// Provides information about the functions parameters.
/// </summary>
public virtual ExcelFunctionParametersInfo ParametersInfo
{
get;
} = ExcelFunctionParametersInfo.Default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class PercentOf : ExcelFunction
{
public override int ArgumentMinLength => 2;
public override string NamespacePrefix => "_xlfn.";

public override bool IsAllowedAsLambdaWithMultipleArguments => true;
public override CompileResult Execute(IList<FunctionArgument> arguments, ParsingContext context)
{
if (arguments.Count > 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace OfficeOpenXml.FormulaParsing.Excel.Functions.MathFunctions
internal class SumV2 : ExcelFunction
{
public override int ArgumentMinLength => 1;
public override string Name => "SUM";

public override CompileResult Execute(IList<FunctionArgument> arguments, ParsingContext context)
{
Expand Down
Loading
Loading