[]
Represents a parameter definition for a custom function.
A Parameter describes the metadata for one function argument, including its
name, description, FunctionValueType, default value, and whether
the argument can accept references or custom objects. Use this class when defining
parameters for CustomFunction or AsyncCustomFunction instances.
public class Parameter
Public Class Parameter
class DiscountPriceFunction : CustomFunction
{
public DiscountPriceFunction(Parameter[] parameters)
: base("DISCOUNT_PRICE", FunctionValueType.Number, parameters)
{
}
public override object Evaluate(object[] arguments, ICalcContext context)
{
return (double)arguments[0] * (1 - (double)arguments[1]);
}
}
Parameter priceParameter = new Parameter("price", "Original price.", FunctionValueType.Number, 0d);
Parameter discountParameter = new Parameter("discount", "Discount rate.", FunctionValueType.Number, 0d);
Workbook.AddCustomFunction(new DiscountPriceFunction(new[] { priceParameter, discountParameter }), true);
worksheet.Range["A1"].Formula = "=DISCOUNT_PRICE(100,0.15)";
object discountedPrice = worksheet.Range["A1"].Value;
| Name | Description |
|---|---|
| Parameter(FunctionValueType) | Initializes an instance of a parameter.
This overload forwards |
| Parameter(FunctionValueType, bool) | Initializes an instance of a parameter. |
| Parameter(FunctionValueType, bool, bool) | Initializes an instance of a parameter. This overload creates a parameter without a name or description and configures whether it accepts references and custom objects. |
| Parameter(FunctionValueType, object) | Initializes an instance of a parameter.
This overload creates a parameter without a name or description and forwards
|
| Parameter(FunctionValueType, object, bool) | Initializes an instance of a parameter. |
| Parameter(string, string, FunctionValueType, object) | Initializes an instance of a parameter.
Creates a parameter definition with the specified name, description, value type, and default value.
This overload forwards |
| Parameter(string, string, FunctionValueType, object, bool) | Initializes an instance of a parameter. |
| Parameter(string, string, FunctionValueType, object, bool, bool) | Initializes an instance of a parameter. |
| Name | Description |
|---|---|
| AcceptCustomObjects | Gets whether the parameter accepts custom objects.
When this property is |
| AcceptReference | Gets whether the parameter accepts a reference value. Use this property to determine whether a custom function parameter can receive a cell or range reference instead of only the referenced value. |
| DefaultValue | Gets the default value of the parameter. This property returns the default value that was specified when the Parameter instance was created. The returned object type depends on the parameter's FunctionValueType. |
| Description | Gets the description of the parameter. This description provides user-facing information about the purpose of the parameter when defining a CustomFunction or AsyncCustomFunction. Returns the description that was specified when the Parameter instance was created. |
| Name | Gets the name of the parameter. This property returns the name specified when the Parameter instance was created. Use the parameter name to identify an argument when defining a CustomFunction or AsyncCustomFunction. |
| ValueType | Gets the value type of the parameter. |