Power Automate: Create Word Document With A Repeating Section

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 ReportSetup The SharePoint ListEnable The Developer Tab In Microsoft WordInsert A Table Into The Word Document TemplateAdd Plain Text Fields To The Word Document Repeating Section
Insert A Repeating Section To The Word Document TemplateSave The Word Document Template To OneDrivePopulate The Word Document With A Repeating SectionGenerate 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.

Power Automate Word Document repeating section
Power Automate Word Document repeating section




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 DateCityUnits SoldTotal SalesAverage Sell Price
6/13/2022Atlanta258,579,200343,168
6/13/2022Boston155,014,515334,301
6/13/2022Chicago3014,172,090472,403
6/13/2022New York4823,879,856497,497
6/13/2022Philadelphia237,564,516328,892
6/14/2022Atlanta3513,676,355390,753
6/14/2022Boston2414,016,960584,040
6/14/2022Chicago156,539,205435,947
6/14/2022New York2411,511,384479,641
6/14/2022Philadelphia3713,901,566375,718
6/15/2022Atlanta103,249,120324,912
6/15/2022Boston2911,682,505402,845
6/15/2022Chicago3418,767,490551,985
6/15/2022New York102,894,770289,477
6/15/2022Philadelphia204,925,920246,296
6/16/2022Atlanta4015,759,440393,986
6/16/2022Boston3511,783,205336,663
6/16/2022Chicago2814,027,972500,999
6/16/2022New York359,522,625272,075
6/16/2022Philadelphia123,795,204316,267
6/17/2022Atlanta4020,885,240522,131
6/17/2022Boston218,385,825399,325
6/17/2022Chicago3812,316,674324,123
6/17/2022New York113,987,852362,532
6/17/2022Philadelphia166,074,896379,681




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.

A





Questions?

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.

Matthew Devaney

Subscribe
Notify of
guest
26 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Lukas
Lukas
2 months ago

Thanks for yet another great blog post! Do you have any idea how to overcome the limitation of not being able to put images into a repeating section of a word template?

Nicole
Nicole
2 months ago

Aw darn, I was all excited to see this post until I got halfway through it and realized that you’re using a premium connector to populate the Word template repeating section… So looks like we’re still stuck with converting HTML to PDF if we need to do this and aren’t allowed to purchase premium connectors…

Christopher
Christopher
2 months ago

Hi Matthew

This would be very useful for teachers when creating report cards. In this scenario, a list of subjects would be listed on each students’ report card along with the grade(marks). The question is how to calculate the average of the grades for each student as part of the instant cloud flow and have it appear at the bottom of the report card.

I enjoy the simplicity and layout of your explanations.

Thanks

Christopher

Andrea
Andrea
2 months ago
Reply to  Christopher

I suppose you could add a field for the average at the bottom of the Word Template (outside the repeating section), then create a Compose action in Power Automate to calculate your average. You can use the result of the Compose action as the input for the average field in the “Populate a MS word template” action. I just tried something similar and it worked.

Andrea
Andrea
2 months ago

This one is also very good. Love it, Matthew – keep them coming 🙂

Josep
Josep
2 months ago

Hi, Matthew,
Great job in this blog. I have a suggestion for you on document generation topic: a Word with an image repeating section.

I’m trying within and out a table but it’s being tough.

James
James
2 months ago

Hi Matthew, I have two questions if you allowed me, please.
1) Base on the table you have as an example, what should I do so that the template only contains rows that correspond to a particular date? Only rows of the day 6/13/2022 for example.
2) What should I do so that one of the columns contains a image?
Thanks in advance.

Jaime Rojas
Jaime Rojas
2 months ago

Hi Matthew, I have two questions if you allowed me, please.
1) Base on the table you have as an example, what should I do so that the template only contains rows that correspond to a particular date? Only rows of the day 6/13/2022 for example.
2) What should I do so that one of the columns contains a image?
Thanks in advance.

Mahesh Caroicar
Mahesh Caroicar
2 months ago

Hi Matthew, great post! By the way, how did you manage to create a dynamic header and footer in a Word document using this method? I tried, but for some reason the image doesn’t show up and the header doesn’t show up dynamically either, any idea why?

Rob Davies
Rob Davies
1 month ago

Matthew, Are you still looking for more document scenarios to work on 🙂 In applying your article to a current project, I have a word template with header and details that continually generates errors. I’m feeding it with JSON datasets from Power Apps, and the automation is “automatically” creating a “for each section” for each dataset. I don’t see the “for each” sections in your example above. (the header only version of this works fine. adding the repeating section data blows up 🙁

Automation Flow example.png
Rohit D
Rohit D
1 month ago

Is there any way to created Bullet points in Word? I could create headers using Repeating section. However it seems Word template connector does not support repeating inside repeating control 😐 . So, technically i can have only one subitem inside header.

1. Header1
a. Subheader1
b. Subheader2
2. Header 2
a. Subheader3

Paul
19 days ago

Very useful, particularly the comment I just read about using Excel to avoid needing a paid for connector.
Thanks for sharing.

Mustafa
Mustafa
14 days ago

Hi,

Sir thanks for your blog, but I am also looking for something like that

I have a Gallery of SharePoint list items and having their attachments (photos)..

I want to create a PDF with some Data of that record along with their images if they have in their record attachments columns.

please help!!!!

arjun
arjun
11 days ago

hey matthew amazing content. I want to know how i can dynamically move on to the second page in the word template once my current page is filled!

Matt
Matt
3 days ago

I’m really grateful for the content you post. You’re one of my ‘go to’ resources

Bronce Gonzalez
Bronce Gonzalez
16 hours ago

Hello Mattew, thank you very much for this I was able to solve my problems. One question, the trial version is over and I want to know the price of this premium feature and how to buy it, can you help me please?