[]
Gets or sets whether the function accepts error values as arguments.
If this property returns true, error values such as #N/A and
#VALUE! can be passed to Evaluate(object[], ICalcContext) for custom
handling. If it returns false, the calculation engine returns the error immediately
instead of passing the error argument to the custom function.
public virtual bool AcceptErrors { get; set; }
Public Overridable Property AcceptErrors As Boolean
CustomFunction function = new HandleErrorFunction();
bool acceptErrors = function.AcceptErrors;
Workbook.AddCustomFunction(function, true);
worksheet.Range["A1"].Formula = "=HANDLEERROR(1/0)";
object result = worksheet.Range["A1"].Value;
class HandleErrorFunction : CustomFunction
{
public HandleErrorFunction()
: base("HANDLEERROR", FunctionValueType.Text, new Parameter[] {
new Parameter(FunctionValueType.Object)
})
{
AcceptErrors = true;
}
public override object Evaluate(object[] arguments, ICalcContext context)
{
return arguments[0] is CalcError ? "Handled error" : arguments[0];
}
}