public abstract class AbstractCalculationEngine
extends java.lang.Object
Remarks
User should not modify any part of the Workbook directly in this implementation(except the calculated result of the custom function, which can be set by CalculationData.CalculatedValue property). Otherwise unexpected result or Exception may be caused. If user needs to change other data than calculated result in the implementation for some custom functions, for example, change cell's formula, style, ...etc., user should gather those data in this implementation and change them out of the scope of formula calculation.Example
class MyEngine extends AbstractCalculationEngine
{
public /*override*/ void calculate(CalculationData data)
{
String funcName = data.getFunctionName().toUpperCase();
if ("MYFUNC".equals(funcName))
{
//do calculation for MYFUNC here
int count = data.getParamCount();
Object res = null;
for (int i = 0; i <count; i++)
{
Object pv = data.getParamValue(i);
if (pv instanceof ReferredArea)
{
ReferredArea ra = (ReferredArea)pv;
pv = ra.getValue(0, 0);
}
//process the parameter here
//res = ...;
}
data.setCalculatedValue(res);
}
}
}
Workbook wb = new Workbook("custom_calc.xlsx");
CalculationOptions opts = new CalculationOptions();
opts.setCustomEngine(new MyEngine());
wb.calculateFormula(opts);
| Constructor and Description |
|---|
AbstractCalculationEngine() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
calculate(CalculationData data)
Calculates one function with given data.
|
boolean |
getProcessBuiltInFunctions()
Whether built-in functions that have been supported by the built-in engine
should be checked and processed by this implementation.
|
boolean |
isParamArrayModeRequired()
Indicates whether this engine needs the parameter to be calculated in array mode.
|
boolean |
isParamLiteralRequired()
Indicates whether this engine needs the literal text of parameter while doing calculation.
|
public abstract void calculate(CalculationData data)
Remarks
User should set the calculated value for given data for all functions(including excel native functions) that he wants to calculate by himself in this implementation.data - the required data to calculate function such as function name, parameters, ...etc.public boolean isParamLiteralRequired()
Remarks
If this custom calculation engine needs the parameter's literal text, more stacks will be required to cache the literal text for parameters and Calculate() method may be called recursively to calculate the parameter's value. Generally the literal text is not needed for calculating formulas and this property should be kept as false for most implementations to get better performance.public boolean isParamArrayModeRequired()
CalculationData.getParamValueInArrayMode(int,int,int) is required when calculating custom
functions, this property needs to be set as true.
Remarks
If this custom calculation engine needs the parameter to be calculated in array mode, more stacks will be required to cache the tree for parameters and Calculate() method may be called recursively to calculate the parameter's value. For performance consideration, if no special requirement, please keep this property as the default value(false).public boolean getProcessBuiltInFunctions()
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2001-2023. All Rights Reserved.