[]
Calculates the result of the custom function.
This method is called by the calculation engine when the custom function is evaluated.
The arguments array contains the argument values passed to the function, and
context provides information about the worksheet cell being calculated.
If AcceptErrors returns true, error values can be passed in
arguments for custom handling. Otherwise, calculation can stop before this method
is called when an argument evaluates to an error.
public abstract object Evaluate(object[] arguments, ICalcContext context)
Public MustOverride Function Evaluate(arguments As Object(), context As ICalcContext) As Object
| Type | Name | Description |
|---|---|---|
| object[] | arguments | The argument values passed to the custom function. Elements can be
evaluated values produced by the formula engine; the array can be empty but is not typically |
| ICalcContext | context | The calculation context that identifies the worksheet, row, and column of the cell being calculated. This value can be used to implement context-sensitive logic. |
| Type | Description |
|---|---|
| object | The calculated result of the custom function. |
CustomFunction function = new DoubleFunction();
ICalcContext calcContext = new SampleCalcContext(worksheet, 0, 0);
object result = function.Evaluate(new object[] { 21d }, calcContext);
class DoubleFunction : CustomFunction
{
public DoubleFunction()
: base("DOUBLE", FunctionValueType.Number)
{
}
public override object Evaluate(object[] arguments, ICalcContext context)
{
return Convert.ToDouble(arguments[0]) * 2;
}
}
class SampleCalcContext : ICalcContext
{
public SampleCalcContext(IWorksheet worksheet, int row, int column)
{
Worksheet = worksheet;
Row = row;
Column = column;
}
public IWorksheet Worksheet { get; }
public int Row { get; }
public int Column { get; }
}