I. Description
When the custom function is executed, the cell where the formula is located is obtained, and the cell where the function is used is output in the log information, so as to monitor whether the report is executed normally or adopt different calculation methods according to the different cell location of the formula.
How to get the cell where the formula is in the custom function? For example, if the custom function is used in the A1 cell, A1 is obtained during execution.
II. Solutions
In the run method of custom function, you can this.getCalculator (). Getcurrentcolumnrow() to get the cell of the formula.
III. Examples
Let's rewrite the sum formula. When we return the final summary value, we also return the cell where the formula is located, as shown in the following figure:
1. For compiling custom functions, see:
2. Compiling custom functions
compile CellSum.java Class generation CellSum.class File and copy to %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\function.
3. Registering custom functions
Start the designer, click server > function manager, name the new function CellSum, select CellSum.class Class, as shown in the figure below:
At this point, the custom function is defined, and you can use it in the designer.
4. Preview effect
Enter 1 in cell A1, 2 in cell A2, and write formula =CellSum (A1, A2) in cell A3 (case insensitive). Save the template preview to get the cell where the formula is located.