Windward DocumentationWindward DesignerDesigner for Microsoft Office FAQsHow Do I Conditionally Color Word Table Cells with Dynamic Data?

How Do I Conditionally Color Word Table Cells with Dynamic Data?

This article will show you how to use conditional formatting in Word to dynamically input a color variable to fill certain table cell backgrounds in your template instead of having to hard code colored cell backgrounds into your table.

For more specific information on the Conditional Formatting Rule Manager, see the How Do I Conditionally Format an Out Tag's Output? article.

 In this example, we'll use a very simple template with a ForEach Tag and some Out Tags and add conditional formatting. We'll use the attached Word template (which connects to the public Northwind SQL database). 

We will start with a simple data table in the document with no conditional formatting applied to the table yet.

Adding One Condition for a Colored Table Cell

To create a variable that holds the value of the color you want in your table cell:

1. Add a Set Tag to your template.

2. Select "Edit Tag".

3. Set a Hex color value for your set tag by entering it into the "Query" pane and selecting the "Select" option for the tag. In this example, we will set the color to green, or #00FF00.

4. Click "Save".

5. Change the nickname of the tag in the Set Tag Properties section of the Windward Ribbon. For this example, we will name it "color1".

6. Change the variable name of the tag in the Set Tag Properties section of the Windward Ribbon. For this example, we will name it "var1".

Now your Set Tag holds the color value that you want to input into the table cells that meet your condition, which we will set next.

To add a conditional formatting rule:

1. Select the Out Tag you would like to conditionally color. For this example we will select the "EmployeeID" tag.

2. Click "Edit Tag".

3. Navigate to the "Properties" pane.

4. Open the "Conditional Formatting Rule Manager".

5. Add a condition for applying the colored table cell. For this example, we will use the condition that the Employee ID = 1, and will type "${varName5.EmployeeID}==1" into the condition text box. 

6. After inputting the condition, open Format Options.

7. Go to the "Cell" tab.

8. In the "Cell Color" option, enter the variable name of your Set Tag. For this example, we set the Set Tag variable name to "var1", so we will type in "=${var1}".

9. Click "Ok" to save your Format Options.

10. Click "OK" to save the Conditional Formatting. 

11. Click "Save" to save your changes to the tag.

Now, your conditional formatting rule is set, and you can test it in your output.

Output your document to a DOCX and view that when the Employee ID is 1, the table cell is filled with the color green. 

You can change the color of the table cell by changing the Hex color value in your Set Tag. You can also add another color to conditionally fill your table cells by adding another Set Tag following the directions at the beginning of this article.

0 Comments

Add your comment

E-Mail me when someone replies to this comment