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.
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:
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.
4. Use a Custom Function
1) Data Preparation
Create a new workbook and add a built-in dataset named Embedded1.
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.
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.
5. Save and Preview
Save and click on Pagination Preview. We can see all the numbers have turned red.