聚合函數的一個特徵是,返回的數值沒有格式化,如以下例子所示,它使用「SUM」:express
數據字段一般返回一個格式化的值,這是一個沒有任何變化的「文本」對象所顯示的值. 格式化「SUM」 的結果, 讓咱們用FastReport中的格式化工具.編輯器
雙擊報表上的對象,切換到'Display Format...' 頁進行設置:函數
這個編輯器在左邊顯示格式的類別, 相應的格式字符顯示在右邊. 咱們選擇 「Number」 分類和 "$1,234.50" 格式. 格式字符串是「Format」函數的一個參數, FastReport使用來實現數字格式的. 格式字符串和小數分隔符能夠改變. 若是將小數分隔符留下空白,則使用當前區域設置值.工具
點擊後ОК並預覽報表,你會發現如今報表的總和是正確的格式:字體
Note the combobox at the top of the dialogue form. If we have more than one expression in an object, we may set different formatting for each expression.this
內部格式化容許你在對象上設置不一樣的格式化字符串表達式. 這個被用於之前版本的FastReport. 如今是過期的(使用格式化對話爲每一個表達式設置不一樣的格式).spa
使用例子, re-size the footer and its object and change the object text to this:設計
Total: [SUM(<Group."ItemsTotal">,MasterData1)] orm
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 monetary format, which we had previously set. This is incorrect:
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 「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(<Group."ItemsTotal">,MasterData1) #n%2,2m]
Number: [COUNT(MasterData1)]
Preview the report to make sure that the object is displayed correctly:
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:
#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 Delphi Format function is used, and for date/time the FormatDateTime function. The syntax for these functions can be found in the Delphi 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:
dd.mm.yyyy – 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」.
在給定的條件下,能夠改變「文本」對象的外觀. 好比, 若是某個對象是負值,則能夠用紅色高亮顯示. 這個特性叫"conditional highlighting". 要使用它,選擇文本對象並單擊工具欄中的 按鈕.你將看到如下窗口:
能夠設置一個或多個條件,每一個條件能夠包含如下的樣式:
·frame; 邊框
·fill; 填充
·font; 字體
·object's visibility. 是否可見
點擊 "Add" 按鈕. 你將看到一個表達式編輯器. 這裏你能夠寫任意返回結果是布爾型的表達式. 多數狀況下,使用"Value" 變量, 他表示當打印打印的值.
讓咱們看如下例子: 打印產品表中的某個字段:
[Products."UnitsInStock"]
咱們想若是值 = 0 打印紅色. 咱們建立如下表達式:
Value = 0
在給定的條件下, 咱們使用"Value" 變量, 它表示打印的值. 若是有多個表達式, 變量的值就是最後一個表達式的值.你可使用數據列來取值:
<Products."UnitsInStock"> = 0
配置以下:
當對象值是0時,顯示紅色. 咱們添加更多的條件, 若是少於10, 打印黃色. 以下:
Value < 10
在有多個條件狀況下, FastReport 檢查全部的條件, 從第一個開始. 若是某個條件知足, FastReport 應用他的樣式設置, 並中止往下. 因此條件的順序很重要. 如下順序是正確的:
1. Value = 0
2. Value < 10
如下順序工做不正常.
1. Value < 10
2. Value = 0
上面的 "Value = 0" 將不被執行, 由於先知足第一個條件, 調整順序使用 和
按鈕。
使用條件突出,很容易建立有一個「帶狀」的報表,數據行交替着色的報表。爲了節省時間,讓咱們用以前設計的「客戶清單」的例子。
放置一個「文本」對象在數據帶上,並延伸到幾乎全部的帶空間:
訪對象根據數據行來改變顏色. 在對象上增長如下條件:
<Line> mod 2 = 1
選擇一個灰色的顏色做爲突出,不太飽和的顏色,但接近白色。如今能夠將其餘對象添加到第一個空的「文本」對象上的數據帶中:
預覽結果以下: