An ever-present question we’re seeing via our support service and from within the Microsoft Power Automate community: How can I insert HTML data into a Microsoft Word Document using Power Automate? It’s pretty simple to use our ‘Populate Word Document‘ action, and this post will provide an example of how to use this feature.
If you’re new to the ‘Populate Word Document‘ action, we recommend reviewing this post’s ‘Populate Word Basic Principles‘ section: Populate a Word or PDF Document using Power Automate V2.
Further detailed guidance can be obtained on our support portal: Populate Word Document – Inserting HTML.
Add SharePoint-rich text data (HTML) to a Word Document
I’m not going to use a real-world scenario as such for this example, as we’ll focus on the mechanics of adding HTML data into a word document. For this basic scenario, I will obtain HTML data from a SharePoint list item column which contains rich text data, as this is an everyday use case. For this demo, I have configured a word document as follows:
I have created a SharePoint list item which contains the following data:
And I have made the following super simple flow:
I’m passing in the template word file when the flow is manually triggered. We then retrieve the item from SharePoint. The file is passed to the ‘Populate Word Document‘ action along with the value of the ‘HTML Example‘ column bounded by a basic JSON structure. We then add the populated document to Onedrive… simple! 🙂
When I execute the flow, it fails with the following error: A error occurred parsing the JSON document provided: After parsing a value, an unexpected character was encountered. This is because the ‘Document Data‘ property has received invalid JSON caused by unescaped double quotes.
HTML markup contains lots of double quotes (also known as speech marks), and if you want to insert HTML data into JSON, then you must escape the double quotes, which is luckily relatively simple and documented in detail here: Escape double quotes in JSON using Power Automate
To resolve this issue I need to wrap the ‘HTML Example‘ property value in the following expression: replace(<dynamicDataHere>,'”‘,’\”‘)
Now I can re-execute the flow successfully:
And validate that the HTML data has been added to the document correctly:
We hope this post provides a helpful example of how to pass HTML data obtained from a PowerApp, website, SharePoint item, etc. and then add the HTML data into a Word document (which could also be converted to PDF!)
Please share any feedback or comments – all are welcome 🙂