ExcelFile.AddUserDefinedFunction Method
Adds a custom formula function to the FlexCel recalculation engine. Note that this formulas are only valid for Excel custom formulas, not for internal ones. For example, you could define "EDATE" since it is a custom formula defined in the Analysis Addin, but you cannot redefine "SUM". Note that if a custom formula with the name already exists, it will be replaced. Names are Case insensitive ("Date" is the same as "DATE").
Also note that some user defined functions come already built in FlexCel, so you might not need to define them. For more information on adding Custom Formulas make sure you read 'Using Excel's user defined functions (UDF)' in the Api Developer Guide and take a look at the at the Excel User Defined Functions C Sharp / netframework example.
Syntax
Namespace: FlexCel.Core
public abstract void AddUserDefinedFunction(TUserDefinedFunctionScope scope, TUserDefinedFunctionLocation location, TUserDefinedFunction userFunction)
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
scope | TUserDefinedFunctionScope | Defines if the custom function will be available globally to all ExcelFile instances or only to the ExcelFile instance where it was added. It is recommended to add functions globally, unless you have different xls files with functions that might have the same name but could be implemented different. | |
location | TUserDefinedFunctionLocation | Defines if the function will be inserted as a reference to a macro in the local sheet or in an external book or addin. This parameter is used only when adding formulas with user defined functions to a sheet. It is not needed or used when recalculating those functions or when reading the text of a formula. |
|
userFunction | TUserDefinedFunction | Formula function we want to add. |