Tables

The Encodian population engine enables JSON data to be easily added to tables within your word document.

This article provides detailed examples for creating the following types of tables:

Table - Simple

Table - Single Column

Table - Total

Table - Filtered Total

Table - Span Rows

Table - Merge Cells

Table - Hide Columns

Table - Dynamic Background Colors

Table - Simple

Example Document: Encodian - Template Syntax - Table Simple.docx

Example JSON Data:

{
"companyName": "Encodian",
"contracts": [
{
"customerName": "Microsoft",
"value": 100000,
"expires": "13/06/2021"
},
{
"customerName": "Encodian",
"value": 6872500,
"expires": "18/02/2029"
},
{
"customerName": "Heritage",
"value": 13549,
"expires": "6/12/2025"
}
]
}

Configure the table within your word document and then populate it as follows to add the relevant JSON properties to each column:

Column 1: <<foreach [contract in contracts]>><<[contract.customerName]>>
Column 2: <<[contract.expires]:"yyyy.MM.dd">>
Column 3: <<[contract.value]>><</foreach>>

mceclip0.png

This generates the following output:

mceclip1.png

Table - Single Column

Example Document: Encodian - Template Syntax - Table Single Column.docx

Example JSON Data:

{
"companyName": "Encodian",
"contracts": [
{
"customerName": "Microsoft",
"value": 100000,
"expires": "13/06/2021"
},
{
"customerName": "Encodian",
"value": 6872500,
"expires": "18/02/2029"
},
{
"customerName": "Heritage",
"value": 13549,
"expires": "6/12/2025"
}
]
}

Configure the table within your word document and then populate it as follows to add the relevant JSON properties to each column:

Row 1 > Column 1: <<foreach [contract in contracts]>>Customer: <<[contract.customerName]>>, Contract Date:<<[contract.expires]:"yyyy.MM.dd">>, Value: £<<[contract.value]>><</foreach -greedy>>

mceclip2.png

This generates the following output:

mceclip3.png

NOTE: the -greedy switch instructs the population engine to treat the property as a single row, if this is not used the output would be as follows:

mceclip5.png

Table - Total

Example Document: Encodian - Template Syntax - Table Totals.docx

Example JSON Data:

{
"companyName": "Encodian",
"contracts": [
{
"customerName": "Microsoft",
"value": 100000,
"expires": "13/06/2021"
},
{
"customerName": "Encodian",
"value": 6872500,
"expires": "18/02/2029"
},
{
"customerName": "Heritage",
"value": 13549,
"expires": "6/12/2025"
}
]
}

Configure the table within your word document and then populate it as follows to add the relevant JSON properties to each column:

Row 1 > Column 1: <<foreach [contract in contracts]>><<[contract.customerName]>>
Row 1 > Column 2: <<[contract.expires]:"yyyy.MM.dd">>
Row 1 > Column 3: £<<[contract.value]>><</foreach>>
Row 2 - Column 1: £<<[contracts.Sum(c =>c.value)]>>

mceclip3.png

This generates the following output:

mceclip4.png

Table - Filtered Total

Example JSON Data:

 
  {
  "Stock": [
    {
      "Item": "Tree", "Fruit": "Apple", "Amount": 20
    },
    {
      "Item": "Bush", "Fruit": "Raspberry", "Amount": 15
    },
    {
      "Item": "Tree", "Fruit": "Plum", "Amount": 12
    },
    {
      "Item": "Tree", "Fruit": "Pear", "Amount": 8
    },
    {
      "Item": "Bush", "Fruit": "Strawberry", "Amount": 28
    },
    {
      "Item": "Bush", "Fruit": "Blackberry", "Amount": 12
    },
  ]
}

Configure the table within your word document and then populate as follows to add the relevant JSON properties to each column:

Row 1 > Column 1:  <<foreach [in Stock]>><<[Item]>><<if[Item==”Tree”]>><<cellMerge>>
Row 1 > Column 2:  <<[Fruit]>>
Row 1 > Column 3:  <<[Amount]>><</if>><</foreach>>
Row 2 > Column 3:  <<[Stock.Where(d => d.Item ==”Tree”).Sum(d => d.Amount)]>>

This generates the following output:

 

Table - Span Rows

Example Document: Encodian - Template Syntax - Table Span Rows.docx

Example JSON Data:

{
"companyName": "Encodian",
"contracts": [
{
"customerName": "Microsoft",
"value": 100000,
"expires": "13/06/2021"
},
{
"customerName": "Encodian",
"value": 6872500,
"expires": "18/02/2029"
},
{
"customerName": "Heritage",
"value": 13549,
"expires": "6/12/2025"
}
]
}

Configure the table within your word document and then populate as follows to add the relevant JSON properties to each column:

Row 1 > Column 1: <<foreach [contract in contracts]>><<[contract.customerName]>>
Row 1 > Column 2: <<[contract.expires]:"yyyy.MM.dd">>
Row 2 > Column 1: £Value: £<<[contract.value]>>
Row 2 > Column 2: <</foreach -greedy>>

NOTE: the -greedy switch instructs the population engine to treat the property as a single row

mceclip0.png

This generates the following output:

mceclip1.png

Table - Merge Cells

Merge table cells with equal text content using the <<cellMerge>> tag. 

By default, a 'cellMerge' tag performs a vertical merge operation. However, you can control this behaviour using the following two options

To perform a horizontal merge, use the -horz switch:

<<cellMerge -horz>>

To perform both a vertical and horizontal merge, use the -both switch:

<<cellMerge -both>>

Example Document: Encodian - Template Syntax - Table Merge.docx

Example JSON Data:

{
"Movies": [
{
"Genre": "Sci-Fi",
"Titles": [
{
"Title": "Star Wars: The Phantom Menace",
"Rating": "8",
"Platform": "Disney",
"Type": "Movie"
},
{
"Title": "Star Trek: The Motion Picture",
"Rating": "8",
"Platform": "Amazon",
"Type": "Movie"
},
{
"Title": "Star Wars: The Mandalorian",
"Rating": "10",
"Platform": "Disney",
"Type": "TV Series"
}
]
},
{
"Genre": "Fantasy",
"Titles": [
{
"Title": "Lord of the Rings: The Rings of Power",
"Rating": "8",
"Platform": "Amazon",
"Type": "Movie"
},
{
"Title": "The Magicians",
"Rating": "6",
"Platform": "Amazon",
"Type": "TV Series"
}
]
}
]
}

Configure the table within your Word documents and then populate as follows to add the relevant JSON properties to each column:

Column 1: <<foreach [movie in Movies]>><<foreach [title in movie.Titles]>><<[movie.Genre]>><<cellMerge>>
Column 2: <<[title.Title]>>
Column 3: <<[title.Rating]>>
Column 4: <<[title.Platform]>>
Column 5: <<[title.Type]>><</foreach>><</foreach>>


This generates the following output:

Tables - Hide Columns

Columns can be hidden via a combination of conditional formatting and the -horz switch. 

Example Document: Encodian - Template Syntax - Hide Columns.docx

Example JSON Data:

{
"ShowAge": false,
"tableData": [
    {
      "Name": "Sally",
      "Age": 35,
      "Department": "Finance"
    },
    {
      "Name": "Susan",
      "Age": 25,
      "Department": "IT"
    }
  ]
}

Configure the template within your Word documents and then populate as follows to add the relevant JSON properties to each cell. A variable is needed so the value of "ShowAge" can be referenced within the foreach loop. 

Outside of the table:  <<var [AgeSwitch = ShowAge]>>
Row 1  > Column 2:    <<if [AgeSwitch] -horz>> Age<</if>>
Row 2 >  Column 1:    <<foreach [in tableData]>><<[Name]>>
Row 2 > Column 2:      <<if [AgeSwitch] -horz>><<[Age]>><</if>>
Row 3 > Column 3:      <<[Department]>><</foreach>>

This generates the following output

 

If the JSON is changed so "ShowAge": true it generates the following output

 

 

Dynamic Table Background Colors

Please refer to Background Colors / Fill Settings syntax documentation.

Syntax Support

Please refer to our Template Design forum where our support team can help with template syntax / you can see solutions to common use cases.

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk