使用表数据字段函数

使用表对象的“表数据”属性页启用表数据并选择来源之后,可使用特殊的“表数据字段”数据源来帮助设计表。“工具箱”的“数据源”窗格中列出了这些“表数据字段”数据源,可将其拖到表单元格来创建链接到数据源的文本对象。有关如何向对象添加“表数据字段”数据源的更多信息,请参阅“创建使用动态数据的表”。

将“表数据字段”数据源链接到对象之后,可使用该对象的“数据源”属性页配置其属性。可指定该属性页中包含的设置来计算“表数据字段”数据源中的求和函数或其他聚合函数。也可以指定函数的计算范围。

以下是可用的函数类型:

以下是可用的范围选项:

可在定义“表数据字段”数据源的表外部使用该数据源,但是执行此操作时,只能对该数据源使用聚合函数。The function defaults to Sum, and for the range you can select All Records or Current Page (Current Group is not supported).此配置的一个典型用法是将某个对象中的总价放到定义该对象的表外部。

例如

Use the examples in this section to become familiar with the basic steps for calculating a sum or other aggregate function in the Table Data Field data source.For each example, you must first create a new table object that is connected to a sample database and then configure a Table Data Field data source, as described in the following procedure.

If you want to go through the steps for both examples, you must create a separate BarTender document for each example.

关闭Creating a Table Object that is Connected to a Database

The examples in this section require that you create a text file database that has a table that includes a Product field, a State field, and a Price field, such as the following sample database.

产品

Dish towel
Coffee mug
叉子
勺子
钳子
Hot pad
Dinner glass
Wine glass
刮勺
Teacup
Juice glass
平底玻璃杯

State
WA
OR
CA
WA
WA
WA
OR
CA
CA
WA
CA
CA
CA

类型
Cutlery
Linens
Glassware
Cutlery
Cutlery
Implement
Linens
Glassware
Glassware
Implement
Glassware
Glassware
Glassware

Price
2.99
12.99
6.99
2.99
2.99
3.99
8.99
3.99
6.99
4.79
5.59
1.99
4.99

After you create the sample database, add a table object to your template that is connected to the database, and then sort the database fields according to the value in the State field.This procedure simultaneously creates a Table Data Field data source that appears on the Data Sources pane of the Toolbox.

关闭To add a table object that is connected to your database and then sort by the State field

  1. 在“对象工具栏”上,单击 图标。也可以单击“创建”菜单上的“”。

  2. 单击“根据数据库创建表”。The Database Setup wizard starts.

  3. Complete the wizard to connect to the sample database.

  4. In the Database Setup dialog, click Sort Order.

  5. In the Available Fields list, double-click State to add it to the Fields to Sort By list, and then click OK.

  6. Click the template at the location where you want to add the table object, and then drag the sizing handles to fit the table within the template.

关闭示例 1:Adding a Sum Aggregate Function

In this example, you will use the Table Properties dialog to configure a new row for the Sum aggregate function and then add the function, which will sum the prices for each State group.

关闭To configure the table properties

  1. 打开“表属性”对话框。要执行此操作,请双击表对象。也可以右键单击对象,然后单击“属性”。

  2. 在导航窗格中,单击“”以显示“”属性页。

  3. In the Rows area, click to add a new row.

  4. In the Row Properties area, under Table Data, follow these steps:

    1. Click Template, and then select Group Footer in the list.

    2. Click Group By, and then click to select the State check box in the list.

    3. Click Page Break, and then select Yes in the list.The table object displays a new, empty row.

  5. Click Close to close the Table Properties dialog.

关闭To add the Sum aggregate function

  1. On the Data Sources pane of the Toolbox, expand the Table 1 node under the Table Data Fields node.

  2. Drag the Price data source to the bottom right table cell under the existing Field:Price cell, as shown.

  3. Right-click the Field:Price object that you just created, and then click Properties to open the Text Properties dialog.

  4. On the Data Source tab, verify the following:

    • The Calculate sum or other aggregate function check box is selected.

    • The Function option is set to Sum.

    • The Range option is set to Current Group.

  5. 单击“关闭”。

  6. Click Print Preview.Your items appear on three labels, grouped by the State field, with the total price calculated for each state and shown in the aggregate field that you added.

关闭示例 2:Adding a Count Aggregate Function

In this example, you will use the Table Properties dialog to configure a new row for the Count aggregate function and then add the function, which will count the number of products that are in each State group.

关闭To configure the table properties

  1. 打开“表属性”对话框。要执行此操作,请双击表对象。也可以右键单击对象,然后单击“属性”。

  2. 在导航窗格中,单击“”以显示“”属性页。

  3. In the Rows area, click to add a new row.

  4. In the Row Properties area, under Table Data, follow these steps:

    1. Click Template, and then select Group Footer in the list.

    2. Click Group By, and then click to select the State check box in the list.

    3. Click Page Break, and then select Yes in the list.

  5. Click Close to close the Table Properties dialog.The table object displays a new, empty row.

关闭To add the Count aggregate function

  1. On the Data Sources pane of the Toolbox, expand the Table 1 node under the Table Data Fields node.

  2. Drag the Product data source to the bottom left table cell under the existing Field:Product cell, as shown.

  3. Right-click the Field:Product object that you just created, and then click Properties to open the Text Properties dialog.

  4. On the Data Source tab, verify the following:

    • The Calculate sum or other aggregate function check box is selected.

    • The Function option is set to Count.

    • The Range option is set to Current Group.

  5. 单击“关闭”以关闭对话框。

  6. Click Print Preview.Your items appear on three labels, grouped by the State field, with the total number of products calculated for each state and shown in the aggregate field that you added.