zoukankan      html  css  js  c++  java
  • [翻译] FastReport 格式化和突出显示

    一:格式化一个值

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

    _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.

    二:内部格式化

    内部格式化允许你在对象上设置不同的格式化字符串表达式. 这个被用于以前版本的FastReport. 现在是过时的(使用格式化对话为每个表达式设置不同的格式).

    使用例子, re-size the footer and its object and change the object text to this:

    Total: [SUM(<Group."ItemsTotal">,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 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

  • 相关阅读:
    Linux下Tomcat日志分割
    adb logcat 命令使用说明
    linux系统下安装两个或多个tomcat
    架构师小跟班:SSL证书免费申请及部署,解决页面样式错乱问题完整攻略
    springboot获取七牛云空间文件列表及下载功能
    Java使用ganymed工具包执行LINUX命令教程
    Java学生信息管理系统源码
    数据库SQL语句性能优化
    Java开发环境系列:一篇能解决你99%问题的排雷日记
    架构师小跟班:教你从零开始申请和配置七牛云免费OSS对象存储(不能再详细了)
  • 原文地址:https://www.cnblogs.com/moon25/p/5534546.html
Copyright © 2011-2022 走看看