TFlexCelUserFunction Class
A class used to define a FlexCel user function, that you can call from a report.
Remarks
To Create a User function:
- Create a new class derived from TFlexCelUserFunction.
- Override the method Evaluate.
- Add the new user function to the report using FlexCelReport.SetUserFunction.
Syntax
Namespace: FlexCel.Report
public abstract class TFlexCelUserFunction
Methods
Name | Description |
---|---|
Evaluate | Override this method on a derived class to implement your own defined function. |
Examples
To define a user function that returns "One" for param = 1; "Two" for param = 2 and "Unknown" on any other case: 1) Define the class:
public class MyUserFunction : TFlexCelUserFunction
{
public override object Evaluate(object[] parameters)
{
if (parameters == null || parameters.Length != 1)
throw new ArgumentException("Invalid number of parameters for user defined function \"MyUserFunction\"");
int p = Convert.ToInt32(parameters[0]);
switch (p)
{
case 1: return "One";
case 2: return "Two";
}
return "Unknown";
}
}
2) Add the function to the report.
MyUserFunction myFuncImpl = new MyUserFunction(); //The MyUserFunction class implements an user defined function.
flexCelReport.SetUserFunction("MF", myFuncImpl); //The name used in Excel will be =MF().
3) Now, you can write "<#MF(1)>" on a template, and it will be replaced by "One".