[]
Adds a custom function to the function set.
The added function can be used in worksheet formulas by the name defined in the specified CustomFunction instance. If a function with the same name already exists in the function set, this method throws an exception.
public static void AddCustomFunction(CustomFunction func, bool canOverride = false)
Public Shared Sub AddCustomFunction(func As CustomFunction, Optional canOverride As Boolean = False)
| Type | Name | Description |
|---|---|---|
| CustomFunction | func | The custom function instance to add. Must not be |
| bool | canOverride | Whether an existing function with the same name can be replaced. |
class MyAddFunction : CustomFunction
{
public MyAddFunction()
: base("WORKBOOK_API_MYADD", FunctionValueType.Number, new Parameter[]
{
new Parameter(FunctionValueType.Number, 0d),
new Parameter(FunctionValueType.Number, 0d)
})
{
}
public override object Evaluate(object[] arguments, ICalcContext context)
{
return (double)arguments[0] + (double)arguments[1];
}
}
Workbook.AddCustomFunction(new MyAddFunction());
worksheet.Range["A1"].Formula = "WORKBOOK_API_MYADD(1,2)";
| Type | Condition |
|---|---|
| ArgumentException | Thrown when a function with the same name already exists and |