Working with Table-Row Data Bands

Contents
[ ]

A table-row data band is a data band which body occupies single or multiple rows of a single document table. The body of such a band starts at the beginning of the first occupied row and ends at the end of the last occupied row as follows.

<<foreach ...>> ... ... ...
... ... ...
... ... ... <</foreach>>

The following examples in this section are given using ds, a DataSet instance containing DataTable and DataRelation objects according to the following data model.

table-row-data-bands-aspose-words-net

The most common use case of a table-row data band is the building of a document table that represents a list of items. You can use a template like the following one to achieve this.

Client Manager Contract Price
<<foreach [c in ds.Contracts]>><<[c.Clients.Name]>> <<[c.Managers.Name]>> <<[c.Price]>><</foreach>>
Total: <<[ds.Contracts.Sum(c => c.Price)]>>

In this case, the engine produces a report as follows.

Client Manager Contract Price
A Company John Smith 1200000
B Ltd. John Smith 750000
C & D John Smith 350000
E Corp. Tony Anderson 650000
F & Partners Tony Anderson 550000
G & Co. July James 350000
H Group July James 250000
I & Sons July James 100000
J Ent. July James 100000
Total: 4300000

To populate a document table with a master-detail data, you can use nested table-row data bands like in the following template.

Manager/Client Contract Price
<<foreach [m in ds.Managers]>><<[m.Name]>> <<[m.Contracts.Sum(c => c.Price)]>>
<<foreach [c in m.Contracts]>> <<[c.Clients.Name]>> <<[c.Price]>><</foreach>><</foreach>>
Total: <<[ds.Contracts.Sum(c => c.Price)]>>

In this case, the engine produces a report as follows.

Manager/Client Contract Price
John Smith 2300000
A Company 1200000
B Ltd. 750000
C & D 350000
Tony Anderson 1200000
E Corp. 650000
F & Partners 550000
July James 800000
G & Co. 350000
H Group 250000
I & Sons 100000
J Ent. 100000
Total: 4300000

You can normally use common data bands nested to table-row data bands as well like in the following template.

Manager Client
<<foreach [m in ds.Managers]>><<[m.Name]>> <<foreach [c in m.Contracts]>><<[c.Clients.Name]>><</foreach>><</foreach>>

In this case, the engine produces a report as follows.

Manager Client
John Smith

A Company

B Ltd.

C & D

Tony Anderson

E Corp.

F & Partners

July James

G & Co.

H Group

I & Sons

J Ent.

Note – Table-column data bands can also be nested to table-row data bands (see “Working with Cross (Pivot) Tables” for details), but not conversely: Nesting of table-row data bands into table-column data bands is forbidden.

A special case is a data band inside a single-column table row. In such a case, if you put opening and closing foreach tags in the same cell, the engine treats a data band formed by these tags as a common one rather than a table-row one by default. The following template illustrates such a scenario.

Manager
<<foreach [m in ds.Managers]>><<[m.Name]>> <</foreach>>

In this case, the engine produces a report as follows.

Managers
John Smith Tony Anderson July James

However, if needed, you can override this behavior making the engine to treat such a data band as a table-row one by specifying a greedy switch like in the following template.

Manager
<<foreach [m in ds.Managers]>><<[m.Name]>><</foreach -greedy>>

In this case, the engine produces a report as follows.

Managers
John Smith
Tony Anderson
July James