[翻译] FastReport 格式化和突出显示

一:格式化一个值

聚合函数的一个特征是,返回的数值没有格式化,如以下例子所示,它使用“SUM”:express

_img141

数据字段一般返回一个格式化的值,这是一个没有任何变化的“文本”对象所显示的值. 格式化“SUM” 的结果, 让咱们用FastReport中的格式化工具.编辑器

双击报表上的对象,切换到'Display Format...' 页进行设置:函数

clip0181

这个编辑器在左边显示格式的类别, 相应的格式字符显示在右边. 咱们选择 “Number” 分类和 "$1,234.50" 格式. 格式字符串是“Format”函数的一个参数, FastReport使用来实现数字格式的. 格式字符串和小数分隔符能够改变. 若是将小数分隔符留下空白,则使用当前区域设置值.工具

点击后ОК并预览报表,你会发现如今报表的总和是正确的格式:字体

_img143

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:

_img144

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:

_img145

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". 要使用它,选择文本对象并单击工具栏中的 btn24 按钮.你将看到如下窗口:

highlight

能够设置一个或多个条件,每一个条件能够包含如下的样式:

·frame;  边框

·fill;  填充

·font;  字体

·object's visibility.    是否可见

点击 "Add" 按钮. 你将看到一个表达式编辑器. 这里你能够写任意返回结果是布尔型的表达式. 多数状况下,使用"Value" 变量, 他表示当打印打印的值.

让咱们看如下例子: 打印产品表中的某个字段:

[Products."UnitsInStock"]

咱们想若是值 = 0 打印红色. 咱们建立如下表达式:

Value = 0

在给定的条件下, 咱们使用"Value" 变量, 它表示打印的值. 若是有多个表达式, 变量的值就是最后一个表达式的值.你可使用数据列来取值:

<Products."UnitsInStock"> = 0

配置以下:

highlightRed

当对象值是0时,显示红色. 咱们添加更多的条件, 若是少于10, 打印黄色. 以下:

Value < 10

在有多个条件状况下, FastReport 检查全部的条件, 从第一个开始. 若是某个条件知足, FastReport 应用他的样式设置, 并中止往下. 因此条件的顺序很重要. 如下顺序是正确的:

1. Value = 0

2. Value < 10

如下顺序工做不正常.

1. Value < 10

2. Value = 0

上面的 "Value = 0" 将不被执行, 由于先知足第一个条件, 调整顺序使用 btn208btn209 按钮。

四:用颜色显示交替的数据行

使用条件突出,很容易建立有一个“带状”的报表,数据行交替着色的报表。为了节省时间,让咱们用以前设计的“客户清单”的例子。

放置一个“文本”对象在数据带上,并延伸到几乎全部的带空间:

clip0183

访对象根据数据行来改变颜色. 在对象上增长如下条件:

<Line> mod 2 = 1

选择一个灰色的颜色做为突出,不太饱和的颜色,但接近白色。如今能够将其余对象添加到第一个空的“文本”对象上的数据带中:

clip0184

预览结果以下:

clip0185

相关文章
相关标签/搜索