Power Automate: Create Word Document With A Repeating Section
Power Automate can populate a word document template with values and convert the document to PDF. Updating single text fields in a PDF is easy but implementing a repeating section requires different code. Repeating sections are typically used to display data tables. The table heading is displayed only one while the rows beneath it are repeated for each record in a SharePoint list (or Dataverse table). In this article I will reveal how to add a repeating section to a Word document template and populate it using Power Automate.
Table Of Contents: • Introduction: The Daily Real Estate Sales Report • Setup The SharePoint List • Enable The Developer Tab In Microsoft Word • Insert A Table Into The Word Document Template • Add Plain Text Fields To The Word Document Repeating Section • Insert A Repeating Section To The Word Document Template • Save The Word Document Template To OneDrive • Populate The Word Document With A Repeating Section • Generate The Word Document With A Repeating Section Using Power Automate
Introduction: The Daily Real Estate Sales Report
Managers at a real estate firm use the Real Estate Sales Report to show how many homes were sold in a market each day. The PDF report is sent via email at the end of each week.
Setup The SharePoint List
Create a SharePoint list called Daily Real Estate Sales with these columns:
- Sale Date (date only)
- City (single-line text)
- Units Sold (number)
- Total Sales (number)
- Average Sell Price (number)
Populate the list with the following data:
|Sale Date||City||Units Sold||Total Sales||Average Sell Price|
Enable The Developer Tab In Microsoft Word
The Daily Real Estate Sales Report is a Word document template that gets populated by Power Automate. Then it gets converted into a PDF and is sent via email. We will work on the Word document template first. Open Microsoft Word and start a new document.
Right-click on any tab in the ribbon and select Customize the Ribbon.
Check the developer tab and then press OK. The developer tab will now appear in the ribbon and we can use it to create fillable fields in the Word document.
Insert A Table Into The Word Document Template
The Daily Sales Report shows multiple rows of data inside a table. Go to the Insert tab and create 5 column and 2 row table.
Add the column headings to the first row of the table and leave the second row of the table blank.
Add Plain Text Fields To The Word Document Repeating Section
Each empty field in the second row will be populated with a text field and then we will use a repeating section to create a new row for each SharePoint list item. Place the cursor inside the empty table cell for Sale Date then click the plain text button on the menu.
A blank plain text field will appear in the table cell. Enable Design mode to see it. Then highlight the plain text field and select Properties.
Input the title and tag for the plain text field. Then press OK.
The title of the plain text field will appear at the start and the end of the field.
Repeat this step for each cell in the second row of the table.
Insert A Repeating Section To The Word Document Template
The second row of the table must be repeated for each row in the Daily Real Estate Sales SharePoint list. Highlight the entire row and select the repeating content button from the menu.
Then select the Properties button and name the repeating section Table Rows.
The Word document repeating section should look like this. We are now finished setting up the template. Save and close the Word document.
Save The Word Document Template To OneDrive
We will use Power Automate to generate the sales report. For Power Automate to access the Word Document template it must be stored in a SharePoint document library or OneDrive. In this tutorial we will use OneDrive. Save the Word document template to the root folder of OneDrive.
Populate The Word Document With A Repeating Section
Open Power Automate and build a new instant cloud flow. Name the flow Real Estate Sales Report. Choose the trigger called Manually trigger a flow and click Create.
Do not add any inputs to the flow.
Insert a Get Items action to obtain all of the Daily Real Estate Sales SharePoint list items.
Add a Select action from the Data Operations actions set to transform the SharePoint list into an array with only the required columns.
Then insert a Populate a Microsoft Word template action and apply it to the Real Estate Sales Report Word document template. Click on the repeating section icon to change the input method.
Then apply the Output of the Select action code to the Table Rows property. This creates a new row in the Word document table for each row in the Daily Real Estate Sales SharePoint list.
Create a file using the Microsoft Word document body.
Convert the Word Document to PDF.
Then Send an Email (V2) with the Daily Real Estate Sales Report as an attachment. We are now done creating the Power Automate flow.
Generate The Word Document With A Repeating Section Using Power Automate
Run the Power Automate flow to generate the Daily Real Estate Sales Report.
The PDF document received via email looks like this.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
If you have any questions about Power Automate: Create Word Document With A Repeating Section please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.