Class ExcelFunction
Base class for Excel function implementations.
Inheritance
System.Object
ExcelFunction
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: EPPlus.dll
public abstract class ExcelFunction
Constructors
Declaration
Declaration
public ExcelFunction(ArgumentCollectionUtil argumentCollectionUtil, ArgumentParsers argumentParsers, CompileResultValidators compileResultValidators)
Parameters
Fields
Declaration
protected readonly ArgumentParsers _argumentParsers
Field Value
Declaration
protected readonly int NumberOfSignificantFigures
Field Value
Type |
Description |
System.Int32 |
|
Properties
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.
Declaration
public abstract int ArgumentMinLength { get; }
Property Value
Type |
Description |
System.Int32 |
|
Describes how the function works with input ranges and returning arrays.
Declaration
public virtual ExcelFunctionArrayBehaviour ArrayBehaviour { get; }
Property Value
Declaration
public virtual bool IsErrorHandlingFunction { get; }
Property Value
Type |
Description |
System.Boolean |
|
If the function returns a different value with the same parameters.
Declaration
public virtual bool IsVolatile { get; }
Property Value
Type |
Description |
System.Boolean |
|
Information of individual arguments of the function used internally by the formula parser .
Declaration
public virtual string NamespacePrefix { get; }
Property Value
Type |
Description |
System.String |
Function argument information
|
Provides information about the functions parameters.
Declaration
public virtual ExcelFunctionParametersInfo ParametersInfo { get; }
Property Value
If the function returns a range reference
Declaration
public virtual bool ReturnsReference { get; }
Property Value
Type |
Description |
System.Boolean |
|
Methods
Helper method for comparison of two doubles.
Declaration
protected bool AreEqual(double d1, double d2)
Parameters
Type |
Name |
Description |
System.Double |
d1 |
|
System.Double |
d2 |
|
Returns
Type |
Description |
System.Boolean |
|
ArgsToDoubleEnumerable(Boolean, Boolean, Boolean, IEnumerable<FunctionArgument>, ParsingContext)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, bool ignoreErrors, bool ignoreNestedSubtotalAggregate, IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Boolean |
ignoreErrors |
If a cell contains an error, that error will be ignored if this method is set to true
|
System.Boolean |
ignoreNestedSubtotalAggregate |
If cells which value comes from the calculation of a SUBTOTAL or an AGGREGATE function should be ignored, set this to true
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
Returns
ArgsToDoubleEnumerable(Boolean, Boolean, Boolean, IEnumerable<FunctionArgument>, ParsingContext, Boolean)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, bool ignoreErrors, bool ignoreNestedSubtotalAggregate, IEnumerable<FunctionArgument> arguments, ParsingContext context, bool ignoreNonNumeric)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Boolean |
ignoreErrors |
If a cell contains an error, that error will be ignored if this method is set to true
|
System.Boolean |
ignoreNestedSubtotalAggregate |
If cells which value comes from the calculation of a SUBTOTAL or an AGGREGATE function should be ignored, set this to true
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
System.Boolean |
ignoreNonNumeric |
|
Returns
ArgsToDoubleEnumerable(Boolean, Boolean, IEnumerable<FunctionArgument>, ParsingContext)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, bool ignoreErrors, IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Boolean |
ignoreErrors |
If a cell contains an error, that error will be ignored if this method is set to true
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
Returns
ArgsToDoubleEnumerable(Boolean, Boolean, IEnumerable<FunctionArgument>, ParsingContext, Boolean)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, bool ignoreNestedSubtotalAggregate, IEnumerable<FunctionArgument> arguments, ParsingContext context, bool ignoreNonNumeric)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Boolean |
ignoreNestedSubtotalAggregate |
If cells which value comes from the calculation of a SUBTOTAL or an AGGREGATE function should be ignored, set this to true
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
System.Boolean |
ignoreNonNumeric |
|
Returns
ArgsToDoubleEnumerable(Boolean, IEnumerable<FunctionArgument>, ParsingContext)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
Returns
ArgsToDoubleEnumerable(Boolean, IEnumerable<FunctionArgument>, ParsingContext, Boolean)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(bool ignoreHiddenCells, IEnumerable<FunctionArgument> arguments, ParsingContext context, bool ignoreNonNumeric)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
System.Boolean |
ignoreNonNumeric |
|
Returns
ArgsToDoubleEnumerable(IEnumerable<FunctionArgument>, ParsingContext)
Will return the arguments as an enumerable of doubles.
Declaration
protected virtual IEnumerable<ExcelDoubleCellValue> ArgsToDoubleEnumerable(IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters
Returns
ArgsToDoubleEnumerableZeroPadded(Boolean, IRangeInfo, ParsingContext)
Declaration
protected virtual IEnumerable<double> ArgsToDoubleEnumerableZeroPadded(bool ignoreHiddenCells, IRangeInfo rangeInfo, ParsingContext context)
Parameters
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.Double> |
|
ArgsToObjectEnumerable(Boolean, Boolean, Boolean, IEnumerable<FunctionArgument>, ParsingContext)
Will return the arguments as an enumerable of objects.
Declaration
protected virtual IEnumerable<object> ArgsToObjectEnumerable(bool ignoreHiddenCells, bool ignoreErrors, bool ignoreNestedSubtotalAggregate, IEnumerable<FunctionArgument> arguments, ParsingContext context)
Parameters
Type |
Name |
Description |
System.Boolean |
ignoreHiddenCells |
If a cell is hidden and this value is true the value of that cell will be ignored
|
System.Boolean |
ignoreErrors |
|
System.Boolean |
ignoreNestedSubtotalAggregate |
|
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
ParsingContext |
context |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.Object> |
|
Declaration
protected string ArgToAddress(IList<FunctionArgument> arguments, int index)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
Returns
Type |
Description |
System.String |
|
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.
Declaration
protected bool ArgToBool(IList<FunctionArgument> arguments, int index)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
Returns
Type |
Description |
System.Boolean |
|
Returns the value of the argument att the position of the 0-based
index
as a System.Double.
Declaration
protected double ArgToDecimal(IList<FunctionArgument> arguments, int index, PrecisionAndRoundingStrategy precisionAndRoundingStrategy = PrecisionAndRoundingStrategy.DotNet)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
PrecisionAndRoundingStrategy |
precisionAndRoundingStrategy |
strategy for handling precision and rounding of double values
|
Returns
Type |
Description |
System.Double |
Value of the argument as an integer.
|
Exceptions
Returns the value of the argument att the position of the 0-based
index
as a System.Double.
If the the value is null, zero will be returned.
Declaration
protected double ArgToDecimal(IList<FunctionArgument> arguments, int index, double valueIfNull)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
System.Double |
valueIfNull |
|
Returns
Type |
Description |
System.Double |
Value of the argument as an integer.
|
Exceptions
Returns the value of the argument att the position of the 0-based
Declaration
protected double ArgToDecimal(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Double |
Value of the argument as a double.
|
Exceptions
Returns the value of the argument att the position of the 0-based
Declaration
protected double ArgToDecimal(object obj, PrecisionAndRoundingStrategy precisionAndRoundingStrategy)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
PrecisionAndRoundingStrategy |
precisionAndRoundingStrategy |
strategy for handling precision and rounding of double values
|
Returns
Type |
Description |
System.Double |
Value of the argument as a double.
|
Exceptions
Returns the value of the argument att the position of the 0-based
index
as an integer.
Declaration
protected int ArgToInt(IList<FunctionArgument> arguments, int index, RoundingMethod roundingMethod)
Parameters
Returns
Type |
Description |
System.Int32 |
Value of the argument as an integer.
|
Exceptions
Returns the value of the argument att the position of the 0-based index
Declaration
protected int ArgToInt(IList<FunctionArgument> arguments, int index, bool ignoreErrors)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
System.Boolean |
ignoreErrors |
If true an Excel error in the cell will be ignored
|
Returns
Type |
Description |
System.Int32 |
Value of the argument as an integer.
|
Exceptions
Returns the value of the argument att the position of the 0-based index
index
as an integer.
Declaration
protected int ArgToInt(IList<FunctionArgument> arguments, int index, int emptyValue = 0)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
System.Int32 |
emptyValue |
Value returned if datatype is empty
|
Returns
Type |
Description |
System.Int32 |
Value of the argument as an integer.
|
Exceptions
Declaration
protected IRangeInfo ArgToRangeInfo(IList<FunctionArgument> arguments, int index)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
Returns
Returns the value of the argument att the position of the 0-based
index
as a string.
Declaration
protected string ArgToString(IList<FunctionArgument> arguments, int index)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IList<FunctionArgument> |
arguments |
|
System.Int32 |
index |
|
Returns
Type |
Description |
System.String |
Value of the argument as a string.
|
BeforeInvoke(ParsingContext)
If overridden, this method is called before Execute is called.
Declaration
public virtual void BeforeInvoke(ParsingContext context)
Parameters
Declaration
protected void CheckForAndHandleExcelError(FunctionArgument arg, out ExcelErrorValue err)
Parameters
Declaration
protected void CheckForAndHandleExcelError(ICellInfo cell, out ExcelErrorValue err)
Parameters
Type |
Name |
Description |
ICellInfo |
cell |
|
ExcelErrorValue |
err |
If the cell contains an error the error will be assigned to this variable
|
Configures parameters of a function that can be arrays (multi-cell ranges)
even if the function itself treats them as single values.
Declaration
public virtual void ConfigureArrayBehaviour(ArrayBehaviourConfig config)
Parameters
Use this method to create a result to return from Excel functions.
Declaration
protected CompileResult CreateAddressResult(IRangeInfo result, DataType dataType)
Parameters
Returns
Use this method to create a result to return from Excel functions.
Declaration
protected CompileResult CreateDynamicArrayResult(object result, DataType dataType)
Parameters
Type |
Name |
Description |
System.Object |
result |
|
DataType |
dataType |
|
Returns
Declaration
protected CompileResult CreateDynamicArrayResult(object result, DataType dataType, FormulaRangeAddress address)
Parameters
Returns
Declaration
protected CompileResult CreateResult(eErrorType errorType)
Parameters
Returns
Use this method to create a result to return from Excel functions.
Declaration
protected CompileResult CreateResult(object result, DataType dataType)
Parameters
Type |
Name |
Description |
System.Object |
result |
|
DataType |
dataType |
|
Returns
Declaration
protected CompileResult CreateResult(object result, DataType dataType, FormulaRangeAddress address)
Parameters
Returns
Declaration
protected double Divide(double left, double right)
Parameters
Type |
Name |
Description |
System.Double |
left |
|
System.Double |
right |
|
Returns
Type |
Description |
System.Double |
|
Execute(IList<FunctionArgument>, ParsingContext)
Declaration
public abstract CompileResult Execute(IList<FunctionArgument> arguments, ParsingContext context)
Parameters
Returns
Returns the value as if the
Declaration
protected double? GetDecimalSingleArgument(FunctionArgument arg)
Parameters
Returns
Type |
Description |
System.Nullable<System.Double> |
|
Used for some Lookupfunctions to indicate that function arguments should
not be compiled before the function is called.
Declaration
protected object GetFirstValue(IEnumerable<FunctionArgument> val)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<FunctionArgument> |
val |
|
Returns
Type |
Description |
System.Object |
|
Declaration
public virtual void GetNewParameterAddress(IList<CompileResult> args, int index, ref Queue<FormulaRangeAddress> addresses)
Parameters
Declaration
protected CompileResult GetResultByObject(object result)
Parameters
Type |
Name |
Description |
System.Object |
result |
|
Returns
Declaration
protected bool IsBool(object val)
Parameters
Type |
Name |
Description |
System.Object |
val |
|
Returns
Type |
Description |
System.Boolean |
|
Declaration
protected bool IsInteger(object n)
Parameters
Type |
Name |
Description |
System.Object |
n |
|
Returns
Type |
Description |
System.Boolean |
|
Declaration
protected bool IsNumeric(object val)
Parameters
Type |
Name |
Description |
System.Object |
val |
|
Returns
Type |
Description |
System.Boolean |
|
Declaration
protected bool IsNumericString(object value)
Parameters
Type |
Name |
Description |
System.Object |
value |
|
Returns
Type |
Description |
System.Boolean |
|
Declaration
protected bool IsString(object val, bool allowNullOrEmpty = true)
Parameters
Type |
Name |
Description |
System.Object |
val |
|
System.Boolean |
allowNullOrEmpty |
|
Returns
Type |
Description |
System.Boolean |
|
Throws an System.ArgumentException if condition
evaluates to true.
Declaration
protected void ThrowArgumentExceptionIf(Func<bool> condition, string message)
Parameters
Type |
Name |
Description |
System.Func<System.Boolean> |
condition |
|
System.String |
message |
|
Exceptions
Type |
Condition |
System.ArgumentException |
|
Throws an System.ArgumentException if condition
evaluates to true.
Declaration
protected void ThrowArgumentExceptionIf(Func<bool> condition, string message, params object[] formats)
Parameters
Type |
Name |
Description |
System.Func<System.Boolean> |
condition |
|
System.String |
message |
|
System.Object[] |
formats |
Formats to the message string.
|
Declaration
protected void ThrowExcelErrorValueException(eErrorType errorType)
Parameters
Declaration
protected void ThrowExcelErrorValueException(ExcelErrorValue value)
Parameters
Throws an System.ArgumentException if condition
evaluates to true.
Declaration
protected void ThrowExcelErrorValueExceptionIf(Func<bool> condition, eErrorType errorType)
Parameters
Type |
Name |
Description |
System.Func<System.Boolean> |
condition |
|
eErrorType |
errorType |
|
Exceptions
This functions validates that the supplied arguments
contains at least
(the value of) minLength
elements. If one of the arguments is an
Excel range the number of cells in
that range will be counted as well.
Declaration
protected void ValidateArguments(IEnumerable<FunctionArgument> arguments, int minLength)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<FunctionArgument> |
arguments |
|
System.Int32 |
minLength |
|
Exceptions
Type |
Condition |
System.ArgumentException |
|
This functions validates that the supplied arguments
contains at least
(the value of) minLength
elements. If one of the arguments is an
Excel range the number of cells in
that range will be counted as well.
Declaration
protected void ValidateArguments(IEnumerable<FunctionArgument> arguments, int minLength, eErrorType errorTypeToThrow)
Parameters