The Encodian Flowr Power Automate connector provides the Merge Word Documents action which allows you to merge up to 1000 Microsoft Word documents into a single word document. Customers who use this action sometimes ask whether it is possible to not only merge the word documents but also merge the actual content within the documents, let’s illustrate why this question is raised.
The Merge Word Documents action merges the actual documents, and not the content… consider the following three documents:
I’ve configured a simple flow to merge these documents:
And upon merging a three-page word document is produced as it is the documents which are merged and not the content:
So how do you merge the actual content of the word documents to produce the following?
The Encodian Populate Word Document action supports merging document content into a single word document. Let’s explore how to do this within Power Automate:
This example flow simply uses a manual trigger but of course, your Flow could be triggered by any action supported by Power Automate (New file created, updated, email received, etc.)
1. Create a new Flow using the ‘Instant cloud flow‘ option
2. Enter a name for the Flow, select the ‘Manually trigger a flow‘ trigger action and click ‘Create‘
3. Add a SharePoint ‘Get files (properties only)‘ action to obtain the files to be merged from SharePoint
3.a. Site Address: Enter the location of the SharePoint site where the target files are stored
3.b. Library Name: Select the SharePoint document library containing the target files
3.c. Limit Entries to Folder: Update as required
4. Add an ‘Initialize variable‘ action which will be used to store the JSON data which we will later send to the Populate Word Document action
4.a. Name: Enter ‘data‘
4.b. Type: Select ‘String‘
4.c. Value: Enter the following data:
{ "files": [
5. Add a SharePoint ‘Get file content‘ action
5.a. Site Address: Set as per step 3.a
5.b. File Identifier: Select the ‘Identifier‘ property provided by the SharePoint ‘Get files (properties only)‘ action
NOTE: This will automatically place the SharePoint ‘Get file content‘ action into an ‘Apply to each‘ loop because SharePoint the ‘Get files (properties only)‘ action returns an array (one or more elements)
6. Add an ‘Append to string variable‘ action and configure as follows to append the file to the data variable
The JSON appended for reference:
{ "file": "@{base64(outputs('Get_file_content')?['body'])}" },
7. Underneath the ‘Apply to each‘ loop add another ‘Append to string variable‘ action
7.a. Name: Enter ‘data‘
7.b. Value: Enter the following data:
] }
At this stage the data variable has been compiled containing all of the documents which we want to ‘merge’ into a single document, the JSON schema for reference:
{ "files": [ { "file": "<base64 content>", }, { "file": "<base64 content>", }, { "file": "<base64 Content>", }, ] }
Reference: <<foreach [f in files]>><<doc[f.file]>><</foreach>>
Please review the Template Syntax for Populate Word Document section on our support site for further guidance.
8. Add another SharePoint ‘Get file content‘ action to obtain the word document template
8.a. Site Address: Enter the location of the SharePoint site where the target file is stored
8.b. File Identifier: Select the relevant file
9. Add the Encodian Populate Word Document action
9.a. File Content: Pass the ‘File Content‘ property provided by the SharePoint ‘Get file content 2‘ action
9.b. Document Data: Pass the ‘data‘ variable
Now, you need to save the output file, for this example I have saved the file to OneDrive:
Your final flow should be similar to this schematic:
Upon execution it should produce a file with merged content:
Hopefully, this post outlines how you can use both the Merge Word Documents action and Populate Word Document action to merge word documents and word document content. Please share your feedback and comments – all are welcome!
Managing Director