Generate Word documents with repeating tables using Power Automate

October 30th 2023
Back to all blogs

The Encodian Flowr Populate Word Document action is incredibly powerful, and today, we show you how to create repeating tables where each table represents a row in Excel. So if you’ve ever wondered about how to generate Word documents with repeating tables using Power Automate, you’re in the right place!

Populate Word Basic Principles

The ‘Populate Word Document‘ action requires two elements

1. File Content: The Microsoft Word Document (DOCX) to populate
2. Document Data: The JSON data to populate the document with

You will configure the Microsoft Word document with tokens, which Power Automate will replace with the JSON data provided at runtime. For our current use case, we want to use the <<foreach>> tokens around a Word table to signify that it will be repeated. Within the table, we will place the tokens to populate the table:

Note how we added formatting instructions to the tokens. The Date field will show values in the format “Monday 23/10/23”, and the start time will show values in the format “05:00 pm”. For further examples of the many formatting options available, please see Expression Results and Formatting.

Download the the above Word template here: DOCX Template

Please note: We have created a corresponding Excel file, which serves as the data source for our repeating tables in Word. Each of the tokens in the Word template corresponds to a column in our Excel table.

Building our Power Automate Flow

Below is an overview of the flow we are going to build before diving into each step in detail:

Step 1: Manual Trigger

We are going to be using a manual trigger in this example. But for your own flow, your trigger could be based on a certain event (e.g. a file being created) or on a recurrence basis (e.g. every Friday).

Step 2: List rows in a table

We need to fetch the data from Excel to pass it through to our document.

Make sure to select Date Time Format ISO 8601 (highlighted in red below).

Step 3: Compose Action

Compose the “value” dynamic field from the List Rows Excel action.

There is currently a bug in Power Automate which would cause the flow to fail due to the array reference provided by Excel being called “value”. However, this bug will be fixed soon, but in the meantime, this workaround solves the issue.

Step 4: Get file content

Retrieve your Word template.

Step 5: Populate Word Document

Here we will generate our Word document using Power Automate

File Content: Insert file content from step 4
Document Data: Provide the JSON from the compose action

{

“itemvalues”: *Compose Outputs*

}

Step 6: Create a file using the output of Step 5

Results

Now, let’s run the flow! We’ll finally see how our flow generates Word documents with repeating tables using Power Automate. We get a table for each row in Excel:

What if your Excel data is not in Excel tables?

Sometimes, we are working with files generated from business systems, and the data is not in Excel tables. However, the Microsoft Excel connector on Power Automate can only access and manipulate data within table content types; luckily for you, there is a solution. Using Encodian Flowr’s Excel actions does not require Excel tables, so now you can Get Rows from Excel, Add Rows to Excel and Delete Rows from Excel no matter the file you have!

Finally…

We hope we have shown one example of how the Encodian Populate Word action can act as an end-to-end document generation tool that can handle formatting, conditional expressions, rich text/HTML, repeating sections, images, and much more!

Please share any feedback or comments – all are welcome 🙂

Author
Alex Rackwitz

Director

Back to all blogs

You might also be interested in...