Cell Content Displays Different Colors

  • Last update:  2020-12-17
  • I. Overview

    There may be a need for displaying numbers in different colors. For fixed texts, you can utilize Display by HTML to achieve it, with the fixed part attached with HTML tags that change the font color. However, it can be tricky to deal with complex data or texts. The article serves as a how-to guide for the custom function method, which aims to add HTML tags to numbers that need a color change.

    441.png

    II. Example

    We will give a demonstration on how to build a custom function, which takes the original text as the first parameter, the desired color as the second, and the type of characters to set color as the third.


    1. Build a Custom Function

    Please go to the following URL for detailed codes:

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


    2. Compile a Custom Function

    Compile the file FlagHtmlColor.java, and copy the generated class file into %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\function.


    3. Add a Custom Function

    Go to the designer. Click on Server -> Function Manager, and add a custom function named FlagHtmlColor, with the class name set up to com.fr.function.FlagHtmlColor as shown below.

    1607071955777391.png


    4. Use a Custom Function

    1) Data Preparation

    Create a new workbook and add a built-in dataset named Embedded1.

    443.png

    2) Use Formula

    Drag and drop the data column to A1, double click on the cell -> Advanced -> assign the formula =FlagHtmlColor($$$,"red","n") to Value as shown below.

    1607072051724762.png

    Note: the third parameter of the formula specifies the type of text that needs to be displayed in different colors, with "n" stands for numbers, "c" for letters and "z" for Chinese characters.

    3) Cell Attributes

    Select cell A1, go to Cell Attributes on the right -> Other -> Advanced -> Display Content, and choose "Display by HTML" as shown below.

    445.png


    5. Save and Preview

    Save and click on Pagination Preview. We can see all the numbers have turned red.


    Attachment List


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

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

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

    不再提示

    10s後關閉

    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