Formatting, Highlighting

Axpert 11

TStructs (Forms)



Axpert Jobs

Axpert Cards

HTML Plug-ins

Users & Roles


Axpert API

Application Var/Params

Publish Axpert Apps

Axpert Mobile






Formatting, Highlighting

  1. Formatting of values
  2. Inline formatting
  3. Conditional highlighting
  4. Coloring alternate data rows

Formatting of values

A feature of aggregate functions is that the returned numerical values are not formatted, as shown by the first example, which uses “SUM”:
Agile developer lowcode Formatting and Highlighting
Data fields usually return a formatted value, which is simply displayed by the “Text” object without any change. To apply formatting to the “SUM” result, let’s use the value formatting tools in FastReport.

Select the object containing the Sum and open the format editor either from ‘Display Format…’ in its context menu or through the “DisplayFormat” property in the object inspector.
Agile developer lowcode Formatting and Highlighting
This editor lists the format categories on the left, the corresponding formats on the right, and the format string and decimal separator for the selected category and format below. We’ll select the “Number” category and the “$1,234.50” format. The format string is an argument for the “Format” function, which FastReport uses to implement number formatting. The format string and decimal separator can be changed. If the decimal separator is left blank then the current regional setup value is used.

After clicking ОК and previewing the report you will see that the Sum in the report is now formatted correctly:

Agile developer lowcode Formatting and Highlighting

Inline formatting

In the example formatting was applied to the object and any expression contained in the object. Everything worked as expected because there was only one expression in the object. However, if we have more than one expression in any object and each requires different formatting then we can use inline formatting.
Using the example, re-size the footer and its object and change the object text to this:
Total: [SUM(,MasterData1)]
Number: [COUNT(MasterData1)]
The total and the number of orders will be displayed in the object.
In the report preview, both of these values are shown in the monetary format, which we had previously set. This is incorrect
Agile developer lowcode Formatting and Highlighting

To display each value in its correct format they need to be formatted individually. To do this we use format tags, which are placed just before the closing square bracket of the expression. In our example, disable formatting for the object (select the “Text (no formatting)” category in the format editor). Now we need to specify the format for just the first expression, as the second one will be displayed correctly by default (i.e. as an integer). Change the object text as follows:
Sum: [SUM(,MasterData1) #n%2,2m]
Number: [COUNT(MasterData1)]
Preview the report to make sure that the object is displayed correctly:
Agile developer lowcode Formatting and Highlighting
The general syntax of format tags is:
[expression #formattag]
Note that the space character between the expression and the “#” symbol is mandatory! The format tag itself might look like this:
#nformat_string – numerical format
#dformat_string – date/time format
#bFalse,True – boolean format
Format_string in each case is the argument to the function used for formatting. So, for numerical formatting, the Format function is used, and for date/time the FormatDateTime function. The syntax for these functions can be found in the help system. Below are several values used in FastReport:
for numerical formatting:
%g – number with the minimal places after the decimal point
%2.2f – number with a fixed number of places after the decimal point
%2.2n – as previous, but with thousands separator
%2.2m – monetary format, accepted by the Windows OS, dependent on the regional settings in the control panel

for date/time formatting: – date as ‘23.12.2003’
dd mmm yyyy – date as ’23 Nov 2003′
dd mmmm yyyy – date as ’23 November 2003′
hh:mm – time as ’23:12′
hh:mm:ss – time as ’23:12:00′
dd mmmm yyyy, hh:mm – date and time as ’23 November 2003, 23:12′

A comma or a dash can be used instead of the dot in the format_string for numerical formatting. This symbol is used as the separator between the integer and the fractional parts of the value. Any other character is not allowed.
For formatting with the “#b” type (boolean), the format_string is entered as two values separated by a comma. The first value corresponds to “False” and the second to “True”.
To save having to memorize all these tags and their meanings there is a convenient shortcut for inserting format tags in the “Text” object editor. Clicking the button opens the format editor described above. When a format is selected it is inserted into the text, and if the cursor is placed just before the closing square bracket the format string will be correctly inserted.

Conditional highlighting

This feature of the ”Text” object allows you to color an object depending on a specified condition being met. The condition can be any expression. We’ll use the example with groups to demonstrate this. Let’s set order totals greater than 5000 to be colored green. Select the object containing the Group.“ItemsTotal” field and click on the “Highlight” button in the designer toolbar. In the highlight editor enter a conditional expression which, if exceeded, will highlight the object; also set the font and background attributes for the highlight.

Agile developer lowcode Formatting and Highlighting

These settings produce this report:

Agile developer lowcode Formatting and Highlighting

Note the conditional expression we used : ‘Value > 5000’. Here ‘Value’ is the value of the DB field to which the object is linked. Alternatively, the condition could be set as ‘ > 5000′. In general, any legal expression may be used.

Coloring alternate data rows

Using conditional highlighting, it is easy to create reports having a “banded” look, where data lines are alternately colored. To save some effort, let’s use the “Customer List” example that we designed previously.

Remove all the “Text” objects from the “MasterData” band. Place a “Text” object on the data band and stretch it to cover almost all of the band space:
Agile developer lowcode Formatting and Highlighting

This object will change its color dependent on the data line number. Select the object and set the following conditional expression in the Highlight tab of the object editor:

mod 2 = 1
Select a gray as the color for highlighting, not too saturated a color, but closer to white. Now the other objects can be added to the data-band on top of the first empty “Text” object:
Agile developer lowcode Formatting and Highlighting
On preview the report produces this output:
Agile developer lowcode Formatting and Highlighting