Get the cell of formula in custom function

  • Last update:January 20, 2021
  • 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:

    企业微信截图_16081955073696.png

    1. For compiling custom functions, see:

    https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/function/CellSum.java


    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.



    Attachment List


    Theme: Secondary Development
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy