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 |
6/13/2022 | Atlanta | 25 | 8,579,200 | 343,168 |
6/13/2022 | Boston | 15 | 5,014,515 | 334,301 |
6/13/2022 | Chicago | 30 | 14,172,090 | 472,403 |
6/13/2022 | New York | 48 | 23,879,856 | 497,497 |
6/13/2022 | Philadelphia | 23 | 7,564,516 | 328,892 |
6/14/2022 | Atlanta | 35 | 13,676,355 | 390,753 |
6/14/2022 | Boston | 24 | 14,016,960 | 584,040 |
6/14/2022 | Chicago | 15 | 6,539,205 | 435,947 |
6/14/2022 | New York | 24 | 11,511,384 | 479,641 |
6/14/2022 | Philadelphia | 37 | 13,901,566 | 375,718 |
6/15/2022 | Atlanta | 10 | 3,249,120 | 324,912 |
6/15/2022 | Boston | 29 | 11,682,505 | 402,845 |
6/15/2022 | Chicago | 34 | 18,767,490 | 551,985 |
6/15/2022 | New York | 10 | 2,894,770 | 289,477 |
6/15/2022 | Philadelphia | 20 | 4,925,920 | 246,296 |
6/16/2022 | Atlanta | 40 | 15,759,440 | 393,986 |
6/16/2022 | Boston | 35 | 11,783,205 | 336,663 |
6/16/2022 | Chicago | 28 | 14,027,972 | 500,999 |
6/16/2022 | New York | 35 | 9,522,625 | 272,075 |
6/16/2022 | Philadelphia | 12 | 3,795,204 | 316,267 |
6/17/2022 | Atlanta | 40 | 20,885,240 | 522,131 |
6/17/2022 | Boston | 21 | 8,385,825 | 399,325 |
6/17/2022 | Chicago | 38 | 12,316,674 | 324,123 |
6/17/2022 | New York | 11 | 3,987,852 | 362,532 |
6/17/2022 | Philadelphia | 16 | 6,074,896 | 379,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.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
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.
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?
Lukas,
It’s not possible to have repeating images with this method. You must use the HTML to PDF method popularized by Shane Young instead or use the paid connector called Plumsail.
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…
Nicole,
I would investigate populating an Excel spreadsheet and converting to PDF if you can’t do a premium license.
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
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.
This one is also very good. Love it, Matthew – keep them coming 🙂
Andrea,
You’re welcome! I wonder if there are any more scenarios I can write on the topic of document generation. Can you think of any?
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.
Josep,
It’s only possible to do if you edit the XML. Sorry, its mega technical and I’ve only see two smart people do it before. Its a great idea in the moment. But I have to wonder who would maintain it after they left their companies.
If you need repeating images use the HTML to PDF method described by Shane Young or go out and purchase a paid license to Plumsail. Both options are viable.
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.
James,
You can use the ‘Filter Array’ data operation to show only the rows on 6/13/2022
https://docs.microsoft.com/en-us/power-automate/data-operations#use-the-filter-array-action
You cannot use an image inside a repeating row while using the Word Document connector. If this is required used the HTML + PDF method instead or buy the Plumsail service and use their connector.
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.
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?
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 🙁
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
Very useful, particularly the comment I just read about using Excel to avoid needing a paid for connector.
Thanks for sharing.
Paul,
That was a clever commenter by an even smarter commenter. I learned from it too!
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!!!!
Hello Mustafa,
It is a limitation of the Word connector. This method does not allow images in the repeating section. You will want to either build an HTML document or use the experimental PDF() feature to achieve your goal.
Hello Matthew, Could you find a solution for it?
Bryan,
Here’s the PDF functional article I wrote: https://www.matthewdevaney.com/power-apps-pdf-function-create-view-download-pdfs/
I have no plans to write about the HTML method. I don’t like creating documents that way. To complicated and too many downsides. Only upside is it’s free.
Hello Matthew, I am getting a error with the populate word solution, when I work with more than one table my document is showing the data in this way (picture)
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!
Arjun,
I don’t understand the meaning of ‘move on dynamically’. A repeating section will do just that, repeat. Each record will be printed to the word document in order. If you would like to go to the next page for a new record I’d suggest a page break.
I’m really grateful for the content you post. You’re one of my ‘go to’ resources
Matt,
You’re welcome fellow person with the same name as me 🙂
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?
Bronce,
It’s currently $15/month for a per user Power Automate license. If you only have a handful of automations several can be one on one account.
https://powerautomate.microsoft.com/en-us/pricing/
Great post. Is there a way to repeat the table headers on each page?
Jennifer,
Yes, it can be done. Here’s some instructions:
https://support.microsoft.com/en-us/office/repeat-table-header-on-subsequent-pages-2ff677e0-3150-464a-a283-fa52794b4b41
Thanks this is very helpful. I am trying to add text above the table like the picture in your example, but for some reason the table keeps starting n the next page. Any idea what I may be doing wrong?
turns out turning on headers to repeat also make the table start at on a new page. I need a barcode in the header but that is currently not possible: Re: Insert Image into header section of a Word Tem… – Power Platform Community (microsoft.com)
Thank you for the blog. I used it and it works. Do you know how i can add a loop to generate multiple documents? I need to use one raw for each document. I have order code in one column and some other columns with data. I need to generate a document for every raw. Is it possible. Would be really helpful.
Thank you very much
Ameer,
I suggest you use the Apply To All action in Power Automate to loop over multiple records and create several documents.
Hi Matthew – this is a really excellent write up. Thanks for taking the time to put this together. I think this will prove to be very beneficial in my SharePoint consulting work. Cheers!
Will,
You’re welcome. Thanks for leaving a nice comment to brighten up my day 🙂
Thank you for this post!
Hello Thank you for the post, it is a great format to follow, i am using it with list rows from dataverse and unfortunately the results get jumbled after i do some work on the flow and save the template, While the total number of rows is correct the data in the table repeats itself for a random number of times. sometimes works great sometimes returns same values. is there a timeout i must add to the flow?
Excellent! I am trying to use a collection that a Power App call makes to the flow. So that collection is converted to JSON in the call.
In the FLOW, I Parse the JSON. I am getting the table with repeated rows but all the rows are blank. 🙂
If you could, I would appreciate help / direction on how to get the Dataverse collection data to appear. 🙂
Thanks. -Sam