Working with Tables

Tables are widely used in almost every area of human endeavor to ensure precision, correctness and comparability of data. They organize text into rows and columns, which can make information easy to consolidate and analyze.

The template syntax, which was extensively described in the previous sections, can be applied to tables in the form of data bands and conditional expressions. This is used to generate a range of output rows given a range of different input data elements.

There are several useful techniques you can use within your template expressions to customize table generation. They can be best illustrated with simple examples provided below.

Generating a Simple Table

The following example shows how to generate a simple In-Table List:

CustomerOrder Price

<<foreach [in customers]>><<[CustomerName]>>

<<[Order.Sum(c => c.Price)]>><</foreach>>

Total

<<[Sum(m => m.Order.Sum(c => c.Price))]>>

Varying Table’s Contents

The following example shows how to generate an In-Table List with a variable contents using conditional expressions:

CustomerOrder Price

<<if [!Any()]>>No data

<<else>><<foreach [in orders]>><<[Product.ProductName]>>

<<[Price]>><</foreach>>

Total

<<[Sum(c => c.Price)]>><</if>>

Data Filtering and Grouping

The following example shows how to generate an In-Table List with data filtering and grouping:

CustomerOrder Price

<<foreach [in orders.Where(c => c.OrderDate.Year == 2020).GroupBy(c => c.Customer).OrderBy(g => g.Key.CustomerName)]>><<[Key.CustomerName]>>

<<[Sum(c => c.Price)]>><</foreach>>

Calculating a Progressive Total

The following example shows how to generate an In-Table List with a progressive total, that requires using a var tag:

CustomerOrder Price

<<var [total = 0.0]>><<foreach [in orders]>><<[Customer.CustomerName]>>

<<var [total = total + Price]>><<[total]>><</foreach>>

Highlighting Rows

The following example shows how to generate an In-Table List with row highlighting:

CustomerOrder Price

<<foreach [in orders]>><<if [Price >= 400]>><<[Customer.CustomerName]>>

<<[Price]>>

<<else>><<[Customer.CustomerName]>>

<<[Price]>><</if>><</foreach>>

Total

<<[Sum(c => c.Price)]>>

Setting Cell’s Background Color

The following example shows how to generate an In-Table List with a background color:

CustomerOrder Price

<<var [total = 0.0]>><<foreach [in orders]>><<backColor[color]>><<[Customer.CustomerName]>><</backColor>>

<<var [total = total + Price]>><<[total]>><</foreach>>

See Also

  • A complete table generation example from the “Quick Start” section.