Class ExcelFunction¶
Namespace: OfficeOpenXml.FormulaParsing.Excel.Functions
Assembly: EPPlus.dll
Base class for Excel function implementations.
Inheritance¶
Derived¶
ConvertFunction
Erf
HiddenValuesHandlingFunction
Text
Inherited Members¶
object.Equals(object?, object?)
object.Equals(object?)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object?, object?)
object.ToString()
Constructors¶
ExcelFunction()¶
Default constructor
Fields¶
NumberOfSignificantFigures¶
Number of significant figures used in roundings, etc.
Field Value¶
Properties¶
ArgumentMinLength¶
Returns the minimum arguments for the function. Number of arguments are validated before calling the execute. If lesser arguments are supplied a #VALUE! error will be returned.
Property Value¶
ArrayBehaviour¶
Describes how the function works with input ranges and returning arrays.
Property Value¶
HandlesVariables¶
Indicates whether the function handles variables (eg. LET, LAMBDA).
Property Value¶
IsAllowedInCalculatedPivotTableField¶
If the function is allowed in a pivot table calculated field. Default is true, if not overridden.
Property Value¶
IsErrorHandlingFunction¶
Indicates that the function is an ErrorHandlingFunction.
Property Value¶
IsVolatile¶
If the function returns a different value with the same parameters.
Property Value¶
NamespacePrefix¶
Information of individual arguments of the function used internally by the formula parser .
Property Value¶
ParametersInfo¶
Provides information about the functions parameters.
Property Value¶
ReturnsReference¶
If the function returns a range reference
Property Value¶
Methods¶
AreEqual(double, double)¶
Helper method for comparison of two doubles.
Parameters¶
d1 double
d2 double
Returns¶
ArgToAddress(IList<FunctionArgument>, int)¶
Returns a string representation of an arguments address.
Parameters¶
arguments IList<FunctionArgument>
index int
Returns¶
ArgToBool(IList<FunctionArgument>, int)¶
If the argument is a boolean value its value will be returned. If the argument is an integer value, true will be returned if its value is not 0, otherwise false.
Parameters¶
arguments IList<FunctionArgument>
index int
Returns¶
ArgToBool(IList<FunctionArgument>, int, bool)¶
If the argument is a boolean value its value will be returned. If the argument is an integer value, true will be returned if its value is not 0, otherwise false. fallback to ValueIfEmpty if datatype is empty
Parameters¶
arguments IList<FunctionArgument>
index int
valueIfEmpty bool
Returns¶
ArgToDecimal(object, out ExcelErrorValue)¶
Returns the value of the argument att the position of the 0-based
Parameters¶
obj object
error ExcelErrorValue
Will be set if the conversion generated an error
Returns¶
Value of the argument as a double.
Exceptions¶
ArgToDecimal(object, PrecisionAndRoundingStrategy, out ExcelErrorValue)¶
Returns the value of the argument att the position of the 0-based
protected double ArgToDecimal(object obj, PrecisionAndRoundingStrategy precisionAndRoundingStrategy, out ExcelErrorValue error)
Parameters¶
obj object
precisionAndRoundingStrategy PrecisionAndRoundingStrategy
strategy for handling precision and rounding of double values
error ExcelErrorValue
An error type if the operation returns an error.
Returns¶
Value of the argument as a double.
Exceptions¶
ArgToDecimal(IList<FunctionArgument>, int, out ExcelErrorValue, PrecisionAndRoundingStrategy)¶
Returns the value of the argument att the position of the 0-based
index as a double.
protected double ArgToDecimal(IList<FunctionArgument> arguments, int index, out ExcelErrorValue error, PrecisionAndRoundingStrategy precisionAndRoundingStrategy = PrecisionAndRoundingStrategy.DotNet)
Parameters¶
arguments IList<FunctionArgument>
index int
error ExcelErrorValue
Will be set if an error occurs during conversion
precisionAndRoundingStrategy PrecisionAndRoundingStrategy
strategy for handling precision and rounding of double values
Returns¶
Value of the argument as an integer.
Exceptions¶
ArgToDecimal(IList<FunctionArgument>, int, double, out ExcelErrorValue)¶
Returns the value of the argument att the position of the 0-based
index as a double.
If the the value is null, zero will be returned.
protected double ArgToDecimal(IList<FunctionArgument> arguments, int index, double valueIfNull, out ExcelErrorValue error)
Parameters¶
arguments IList<FunctionArgument>
index int
valueIfNull double
error ExcelErrorValue
Will be set if an error occurs during conversion
Returns¶
Value of the argument as an integer.
Exceptions¶
ArgToInt(IList<FunctionArgument>, int, out ExcelErrorValue, int)¶
Returns the value of the argument att the position of the 0-based index
index as an integer.
protected int ArgToInt(IList<FunctionArgument> arguments, int index, out ExcelErrorValue error, int emptyValue = 0)
Parameters¶
arguments IList<FunctionArgument>
index int
error ExcelErrorValue
If an error occurs during the conversion it will be returned via this parameter
emptyValue int
Value returned if datatype is empty
Returns¶
Value of the argument as an integer.
Exceptions¶
ArgToInt(IList<FunctionArgument>, int, bool, out ExcelErrorValue)¶
Returns the value of the argument att the position of the 0-based index
protected int ArgToInt(IList<FunctionArgument> arguments, int index, bool ignoreErrors, out ExcelErrorValue error)
Parameters¶
arguments IList<FunctionArgument>
index int
ignoreErrors bool
If true an Excel error in the cell will be ignored
error ExcelErrorValue
If an error occurs during the conversion it will be returned via this parameter
Returns¶
Value of the argument as an integer.
Exceptions¶
ArgToInt(IList<FunctionArgument>, int, RoundingMethod)¶
Returns the value of the argument att the position of the 0-based
index as an integer.
Parameters¶
arguments IList<FunctionArgument>
index int
roundingMethod RoundingMethod
Returns¶
Value of the argument as an integer.
Exceptions¶
ArgToRangeInfo(IList<FunctionArgument>, int)¶
Parameters¶
arguments IList<FunctionArgument>
index int
Returns¶
ArgToString(IList<FunctionArgument>, int)¶
Returns the value of the argument att the position of the 0-based
index as a string.
Parameters¶
arguments IList<FunctionArgument>
index int
Returns¶
Value of the argument as a string.
ArgsToDoubleEnumerable(IEnumerable<FunctionArgument>, ParsingContext, out ExcelErrorValue)¶
Will return the arguments as an enumerable of doubles.
protected virtual IList<double> ArgsToDoubleEnumerable(IEnumerable<FunctionArgument> arguments, ParsingContext context, out ExcelErrorValue error)
Parameters¶
arguments IEnumerable<FunctionArgument>
context ParsingContext
error ExcelErrorValue
Returns¶
ArgsToDoubleEnumerable(IEnumerable<FunctionArgument>, ParsingContext, Action<DoubleEnumerableParseOptions>, out ExcelErrorValue)¶
Will return the arguments as an enumerable of doubles.
protected virtual IList<double> ArgsToDoubleEnumerable(IEnumerable<FunctionArgument> arguments, ParsingContext context, Action<DoubleEnumerableParseOptions> configHandler, out ExcelErrorValue error)
Parameters¶
arguments IEnumerable<FunctionArgument>
context ParsingContext
configHandler Action<DoubleEnumerableParseOptions>
error ExcelErrorValue
Returns¶
Exceptions¶
ArgsToDoubleEnumerable(FunctionArgument, ParsingContext, Action<DoubleEnumerableParseOptions>, out ExcelErrorValue)¶
Will return the arguments as an enumerable of doubles.
protected virtual IList<double> ArgsToDoubleEnumerable(FunctionArgument argument, ParsingContext context, Action<DoubleEnumerableParseOptions> configHandler, out ExcelErrorValue error)
Parameters¶
argument FunctionArgument
context ParsingContext
configHandler Action<DoubleEnumerableParseOptions>
error ExcelErrorValue
Returns¶
ArgsToDoubleEnumerable(FunctionArgument, ParsingContext, out ExcelErrorValue)¶
Will return the arguments as an enumerable of doubles using default parameters
protected virtual IList<double> ArgsToDoubleEnumerable(FunctionArgument argument, ParsingContext context, out ExcelErrorValue error)
Parameters¶
argument FunctionArgument
context ParsingContext
error ExcelErrorValue
Returns¶
ArgsToObjectEnumerable(bool, bool, bool, IEnumerable<FunctionArgument>, ParsingContext)¶
Will return the arguments as an enumerable of objects.
protected virtual IEnumerable<object> ArgsToObjectEnumerable(bool ignoreHiddenCells, bool ignoreErrors, bool ignoreNestedSubtotalAggregate, IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters¶
ignoreHiddenCells bool
If a cell is hidden and this value is true the value of that cell will be ignored
ignoreErrors bool
ignoreNestedSubtotalAggregate bool
arguments IEnumerable<FunctionArgument>
context ParsingContext
Returns¶
CheckForAndHandleExcelError(FunctionArgument, out ExcelErrorValue)¶
if the supplied arg contains an Excel error
an ExcelErrorValueException with that errorcode will be thrown
Parameters¶
arg FunctionArgument
err ExcelErrorValue
If the cell contains an error the error will be assigned to this variable
CheckForAndHandleExcelError(ICellInfo, out ExcelErrorValue)¶
If the supplied cell contains an Excel error
an ExcelErrorValueException with that errorcode will be thrown
Parameters¶
cell ICellInfo
err ExcelErrorValue
If the cell contains an error the error will be assigned to this variable
ConfigureArrayBehaviour(ArrayBehaviourConfig)¶
Configures parameters of a function that can be arrays (multi-cell ranges) even if the function itself treats them as single values.
Parameters¶
config ArrayBehaviourConfig
CreateAddressResult(IRangeInfo, DataType)¶
Use this method to create a result to return from Excel functions.
Parameters¶
result IRangeInfo
dataType DataType
Returns¶
CreateDynamicArrayResult(object, DataType)¶
Use this method to create a result to return from Excel functions.
Parameters¶
result object
dataType DataType
Returns¶
CreateDynamicArrayResult(object, DataType, FormulaRangeAddress)¶
Use this method to create a result to return from Excel functions.
protected CompileResult CreateDynamicArrayResult(object result, DataType dataType, FormulaRangeAddress address)
Parameters¶
result object
dataType DataType
address FormulaRangeAddress
Returns¶
CreateResult(object, DataType)¶
Use this method to create a result to return from Excel functions.
Parameters¶
result object
dataType DataType
Returns¶
CreateResult(object, DataType, FormulaRangeAddress)¶
Use this method to create a result to return from Excel functions.
Parameters¶
result object
dataType DataType
address FormulaRangeAddress
Returns¶
CreateResult(eErrorType)¶
Use this method to create a result to return from Excel functions.
Parameters¶
errorType eErrorType
Returns¶
Divide(double, double)¶
Divides two numbers. If right is zero double.PositiveInfinity will be returned.
Parameters¶
left double
Numerator
right double
Denominator
Returns¶
Execute(IList<FunctionArgument>, ParsingContext)¶
Parameters¶
arguments IList<FunctionArgument>
Arguments to the function, each argument can contain primitive types, lists or IRangeInfo?text=Excel+ranges
context ParsingContext
The ParsingContext contains various data that can be useful in functions.
Returns¶
A CompileResult containing the calculated value
GetDecimalSingleArgument(FunctionArgument)¶
Returns the value as if the
Parameters¶
arg FunctionArgument
Returns¶
GetFirstValue(IEnumerable<FunctionArgument>)¶
Used for some Lookupfunctions to indicate that function arguments should not be compiled before the function is called.
Parameters¶
val IEnumerable<FunctionArgument>
Returns¶
GetNewParameterAddress(IList<CompileResult>, int, ref Queue<FormulaRangeAddress>)¶
If overridden, this method will be called before the Execute(IList<FunctionArgument>, ParsingContext) method is called with the arguments for any parameter having ParametersInfo set to AdjustParameterAddress and that argument is a range with an address. It can be used to narrow the dependency check for the function returning a queue with addresses to check dependency before executing.
public virtual void GetNewParameterAddress(IList<CompileResult> args, int index, ref Queue<FormulaRangeAddress> addresses)
Parameters¶
args IList<CompileResult>
The function arguments that will be supplied to the execute method.
index int
The index of the argument that should be adjusted.
addresses Queue<FormulaRangeAddress>
A queue of addresses that will be calculated before calling the Execute function.
GetResultByObject(object)¶
Get result by object
Parameters¶
result object
Returns¶
IsBool(object)¶
Is bool
Parameters¶
val object
Returns¶
IsInteger(object)¶
Returns true if the parameter n is an integer, otherwise false.
Parameters¶
n object
The value to test
Returns¶
IsNumeric(object)¶
Is numeric
Parameters¶
val object
Returns¶
IsNumericString(object)¶
Returns true if the parameter value is a numeric string, otherwise false.
Parameters¶
value object
The value to test
Returns¶
IsString(object, bool)¶
Is string
Parameters¶
val object
allowNullOrEmpty bool
Returns¶
ThrowArgumentExceptionIf(Func<bool>, string)¶
Throws an ArgumentException if condition evaluates to true.
Parameters¶
message string
Exceptions¶
ThrowArgumentExceptionIf(Func<bool>, string, params object[])¶
Throws an ArgumentException if condition evaluates to true.
protected void ThrowArgumentExceptionIf(Func<bool> condition, string message, params object[] formats)
Parameters¶
message string
formats object[]
Formats to the message string.
ThrowExcelErrorValueException(eErrorType)¶
Throws an ExcelErrorValueException with the given errorType set.
Parameters¶
errorType eErrorType
ThrowExcelErrorValueException(ExcelErrorValue)¶
Throws an ExcelErrorValueException with the type of given value set.
Parameters¶
value ExcelErrorValue
ThrowExcelErrorValueExceptionIf(Func<bool>, eErrorType)¶
Throws an ArgumentException if condition evaluates to true.
Parameters¶
errorType eErrorType
Exceptions¶
ValidateArguments(IEnumerable<FunctionArgument>, int, eErrorType)¶
This functions validates that the supplied arguments contains at least
(the value of) minLength elements. If one of the arguments is an
IRangeInfo?text=Excel+range the number of cells in
that range will be counted as well.
[Obsolete("Don't use this method from EPPlus 7.x and up. Use property ArgumentMinLength instead.")]
protected void ValidateArguments(IEnumerable<FunctionArgument> arguments, int minLength, eErrorType errorTypeToThrow)
Parameters¶
arguments IEnumerable<FunctionArgument>
minLength int
errorTypeToThrow eErrorType
The eErrorType of the ExcelErrorValueException that will be thrown if minLength is not met.
ValidateArguments(IEnumerable<FunctionArgument>, int)¶
This functions validates that the supplied arguments contains at least
(the value of) minLength elements. If one of the arguments is an
IRangeInfo?text=Excel+range the number of cells in
that range will be counted as well.
[Obsolete("Don't use this method from EPPlus 7.x and up. Use property ArgumentMinLength instead.")]
protected void ValidateArguments(IEnumerable<FunctionArgument> arguments, int minLength)
Parameters¶
arguments IEnumerable<FunctionArgument>
minLength int