I. Overview
1. Problem description
In the process of making the report, we can set the alignment of the entire row or column of cells uniformly through theAlignment in the cell style. As shown below:
But if you want cells in a row (or column) to have different alignments under different conditions, how to achieve it?
For example, the North China region is horizontally aligned to the left, and the East China region is horizontally aligned to the right, as shown in the following figure:
2. Solutions
By adding Conditional Formatting>Add>New to the cell, the new value is expressed by HTML formula, and then the cell content is displayed in HTML.
Horizontal Alignment | Formula |
---|---|
Left horizontally | CONCATENATE("<div align='left'>"+$$$+"</div>") |
Center horizontally | CONCATENATE("<div align='center'>"+$$$+"</div>") |
Right horizontally | CONCATENATE("<div align='right'>"+$$$+"</div>") |
Note: It can also be achieved through the Cell alignment condition attribute plug-in.
II. Example
1. Prepare data
Create a new general report, create a new database query ds1, the SQL query statement is: SELECT * FROM SALES_VOLUME.
2. Template settings
Drag the field in the data set to the cell and set the content to Center, and change the Data Setting of cell A2 to List. The design table style is shown in the figure below:
3. Set conditional formatting
1) Select cell A2, add two conditional formattings, and rename them to North China Left Alignmentand China East Right Alignment.
2) North China left alignment: when the cell value is equal to China North, the new value is the formula: CONCATENATE("<div align='left'>"+$$$+"</div>")
The function of CONCATENATE() is to combine multiple strings into one string.
3) The same applies to East China right alignment. The new value is the formula: CONCATENATE("<div align='right'>"+$$$+"</div>")
4. Set cell display content
Set the Cell Attributes> Other> Display Content of cell A2 to Display by HTML. As shown below:
5. Effect preview
1) PC terminal
Save the report, click Pagination Preview, the effect is consistent with the rendering in section I.1.Problem description.
2) Mobile
Both App and HTML5 are supported, and the effect is shown in the figure below:
III. Template download
The completed template can be found in:
%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\Change the cell alignment by using new values.cpt
Click to download the template: Change the cell alignment by using new values.cpt