[]
A Parameter describes the metadata for one function argument, including its name, description, value type, default value, and whether the argument can accept references or custom objects. Use this class when defining parameters for CustomFunction or AsyncCustomFunction instances.
class DiscountPriceFunction extends CustomFunction {
DiscountPriceFunction(Parameter[] parameters) {
super("DISCOUNT_PRICE", FunctionValueType.Number, parameters);
}
@Override
public 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 Parameter[] {
priceParameter,
discountParameter
}), true);
worksheet.getRange("A1").setFormula("=DISCOUNT_PRICE(100,0.15)");
Object discountedPrice = worksheet.getRange("A1").getValue();
Parameter(FunctionValueType valueType) Parameter(FunctionValueType valueType,
boolean acceptReference) Parameter(FunctionValueType valueType,
boolean acceptReference,
boolean acceptCustomObjects) Parameter(FunctionValueType valueType,
Object defaultValue) Parameter(FunctionValueType valueType,
Object defaultValue,
boolean acceptReference) Parameter(String name,
String description,
FunctionValueType valueType,
Object defaultValue) Parameter(String name,
String description,
FunctionValueType valueType,
Object defaultValue,
boolean acceptReference) Parameter(String name,
String description,
FunctionValueType valueType,
Object defaultValue,
boolean acceptReference,
boolean acceptCustomObjects) final booleanfinal Objectfinal Stringfinal StringgetName()final FunctionValueTypeThis overload forwards null as the default value to Parameter(FunctionValueType,Object).
valueType - The value type of the parameter.This overload creates a parameter without a name, description, or default value and forwards null as the default value.
valueType - The value type of the parameter.acceptReference - true if this parameter can accept a reference; otherwise, false.This overload creates a parameter without a name or description and stores the specified default value for the specified FunctionValueType.
valueType - The value type of the parameter.defaultValue - The default value of the parameter.This overload creates a parameter without a name or description and forwards null for both values.
valueType - The value type of the parameter.defaultValue - The default value of the parameter. This value can be null.acceptReference - If this parameter can accept reference.Creates a parameter definition with the specified name, description, value type, and default value. This overload forwards false for the acceptReference argument.
name - The name of the parameter. This value can be null.description - The description of the parameter. This value can be null.valueType - The value type of the parameter.defaultValue - The default value of the parameter. This value can be null.Creates a parameter definition with the specified name, description, value type, and default value. This overload forwards false for the acceptCustomObjects argument to Parameter(String,String,FunctionValueType,Object,boolean,boolean).
name - The name of the parameter. This value can be null.description - The description of the parameter. This value can be null.valueType - The value type of the parameter.defaultValue - The default value of the parameter. This value can be null.acceptReference - true if this parameter can accept a reference; otherwise, false.This overload creates a parameter without a name, description, or default value and forwards null for those values to Parameter(String,String,FunctionValueType,Object,boolean,boolean).
Set acceptCustomObjects to true to allow custom objects when valueType is FunctionValueType.Object.
valueType - The value type of the parameter.acceptReference - If this parameter can accept reference.acceptCustomObjects - Accepts custom objects if value type is FunctionValueType.Object.Use this constructor when defining metadata for a custom function parameter, including whether the parameter accepts references and whether custom objects are allowed when the value type is FunctionValueType.Object.
name - The name of the parameter.description - The description of the parameter.valueType - The value type of the parameter.defaultValue - The default value of the parameter.acceptReference - true if this parameter can accept a reference; otherwise, false.acceptCustomObjects - true if this parameter accepts custom objects when valueType is FunctionValueType.Object; otherwise, false.This method returns the name specified when the Parameter instance was created. Use the parameter name to identify an argument when defining a CustomFunction or AsyncCustomFunction.
Parameter priceParameter = new Parameter("price", "Original price.", FunctionValueType.Number, 0d);
Parameter discountParameter = new Parameter("discount", "Discount rate.", FunctionValueType.Number, 0d);
CustomFunction function = new DiscountPriceFunction(new Parameter[] {
priceParameter,
discountParameter
});
Workbook.AddCustomFunction(function, true);
String name = priceParameter.getName();
null if no name was specified.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.
Parameter priceParameter = new Parameter("price", "Original price.", FunctionValueType.Number, 0d);
Parameter discountParameter = new Parameter("discount", "Discount rate.", FunctionValueType.Number, 0d);
CustomFunction function = new DiscountPriceFunction(new Parameter[] {
priceParameter,
discountParameter
});
Workbook.AddCustomFunction(function, true);
String description = discountParameter.getDescription();
null if no description was specified.This method returns the FunctionValueType that defines what kind of value the parameter accepts, such as number, text, boolean, variant, or object. The returned value is the type that was specified when the Parameter instance was created.
Parameter amountParameter = new Parameter(FunctionValueType.Number, 0d);
CustomFunction function = new AddTaxFunction(new Parameter[] {
amountParameter,
new Parameter(FunctionValueType.Number, 0.08d)
});
Workbook.AddCustomFunction(function, true);
FunctionValueType valueType = amountParameter.getValueType();
This method returns the default value that was specified when the Parameter instance was created. The returned object type depends on the parameter's FunctionValueType.
Parameter taxRateParameter = new Parameter(FunctionValueType.Number, 0.08d);
CustomFunction function = new AddTaxFunction(new Parameter[] {
new Parameter(FunctionValueType.Number),
taxRateParameter
});
Workbook.AddCustomFunction(function, true);
worksheet.getRange("A1").setFormula("=ADD_TAX(100)");
Object total = worksheet.getRange("A1").getValue();
Object defaultValue = taxRateParameter.getDefaultValue();
null if no default value was specified.Use this property to determine whether a custom function parameter can receive a cell or range reference instead of only the referenced value.
Parameter rangeParameter = new Parameter(FunctionValueType.Object, true);
CustomFunction function = new SumRangeFunction(new Parameter[] { rangeParameter });
Workbook.AddCustomFunction(function, true);
worksheet.getRange("A1:A3").setValue(new Object[][] {{1}, {2}, {3}});
worksheet.getRange("B1").setFormula("=SUM_RANGE(A1:A3)");
boolean acceptReference = rangeParameter.getAcceptReference();
true if the parameter accepts a reference value; otherwise, false.