Foolproof Power Automate HTML Table Styling
You can use Power Automate to an send email with a formatted and styled HTML table. With the help of the Create HTML Table action any set of SharePoint list items can be quickly converted into an HTML table. But that table will look pretty plain unless you apply some CSS to it. In this article I will show you my foolproof Power Automate method for HTML table styling.
Table of Contents
• Introduction: The Daily Cash Receipts Report
• Setup The SharePoint List
• Create An HTML Table From SharePoint List Items
• Design And Apply An HTML Table Style
• Send An Email With An HTML Table Style
• Formatting Dates And Numbers In An HTML Table
Introduction: The Daily Cash Receipts Report
Salespeople at a bus manufacturing company receives a daily cash receipts report from the accounting team. The email contains a formatted HTML table showing when payment was received, which customer paid and the amount.
Setup The SharePoint List
Create a new SharePoint list named Cash Receipts with the following columns:
- Customer Name (text)
- Received Date (date only)
- Amount (number)
Populate the SharePoint list with the following data:
Customer Name | Received Date | Amount |
Burton Bus Lines | 1/12/2024 | 462000 |
Texas Tours, LLC | 1/12/2024 | 2161000 |
Coach America | 1/12/2024 | 2851000 |
State Of New York | 1/12/2024 | 955000 |
Polk County | 1/12/2024 | 513000 |
Jefferson Bus Lines | 1/12/2024 | 1456000 |
California Coach | 1/12/2024 | 525000 |
Las Vegas Touring Company | 1/12/2024 | 2914000 |
After setting up the SharePoint list it will look like this.
Create An HTML Table From SharePoint List Items
We want to get all of the items in the Cash Receipts SharePoint list and convert them into an HTML table. Open Power Automate and create a new flow with an instant trigger. Then add the SharePoint – Get Items action and select the Cash Receipts list.
The SharePoint list includes many columns that we do not want to appear in the email. We only want to show the Received Date, Customer Name and Amount. To show only the desired columns insert the Data Operations – Select action and configure it as shown below.
Then add a Data Operations – Create HTML table and use the output of the Select action in the from field. The flow now result in a plain HTML table with no styling applied.
Design And Apply An HTML Table Style
To create the HTML table style we will use the DivTable Table Styler online tool. Scroll down to the style editor and select the NO STYLE theme. Then setup the HTML table style exactly as shown below.
Below the Style Editor there is a WYSIWYG preview that shows a preview of what the table will look like. After the desired style has been achieved copy the copy in the CSS textbox to the clipboard.
Paste the code into Windows Notepad and remove the “.unstyledTable” CSS class from it entirely. Then add style tags to the start and end of the code.
<style>
table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid #AAAAAA;
padding: 3px 10px;
}
table tr:nth-child(even) {
background: #D9E1F2;
}
table thead {
background: #4472C4;
}
table thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
text-align: left;
}
table tfoot {
font-weight: bold;
}
</style>
Insert a Data Operations – Compose action into the flow and copy + paste the code from Windows Notepad into it. Add the output of the Create HTML table action at the bottom. When placed in the body of an email this Compose actions output will display a styled HTML table.
Send An Email With An HTML Table Style
Now we have everything needed to include in the email. Add an Office 365 Outlook – Send An Email (V2) action with “Daily Cash Receipts – January 12, 2024” as the subject. Switch the body to Code View and fill it with the Compose CSS action output.
Test run the flow.
When the email is received it will look like this.
Formatting Dates And Numbers In An HTML Table
The Received Date and Amount are shown using the default date & number formats respectively. We can change that with some additional updates to the flow.
Go to the Select action of the flow and change the Received Date value to this code. The date showing as 2024-01-12 will now appear as 1/12/2024.
formatDateTime(item()?['ReceivedDate'], 'M/d/yyyy')
Then update the Amount code to this instead. The number showing as 462000 will now appear as $462,000.00
formatNumber(item()?['Amount'], '$#,##0.00')
Perform another flow test run to see the dates and numbers in their desired formats.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps & Power Automate articles sent to your inbox each week for FREE
Questions?
If you have any questions or feedback about Foolproof Power Automate HTML Table Styling 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.
I used a similar flow for an incident reporting task. we used it to inform staff when they have missed a deadline.
This is out of context, out of PowerApps and Power Automate, which one do you love the most?
Udula,
I enjoy apps more because they have a visual problem solving component when deciding on the UI. And end users are aware of apps more than they are of an automation.
Cool stuff Matt
Thanks Raghu 🙂
Great article Matthew. I did this similar setup a couple of years ago, however, the issue I encountered was when you save to a PDF and the table is longer than a single page. Then pagination, footers, repeating headers seem not to be a reality for Microsoft. Not every table is very small and confined to email.
Thanks again.
Carl,
In truth, I think Microsoft does not give the ability to do the Populate A Word Document action which is superior to HTML because they want us to upgrade to a premium license. This leads to suboptimal workarounds. And yes, the HTML method has many limitations. But the worst limitation in my mind is maintainability.
Great post. Thanks for leaving it!
This is really cool, thank you!
One thing we tried was to create a sub-flow with the styling only.
Then other flows call this one and the e-mail styling is consistent across flows.
Great stuff, Matt. Question: Would it be possible to make an cell in the HTML table a clickable href link? I’ve tried to put the <a href.. etc.> code in, but of course it renders as literal text, not as a link. Any idea?
Tomas Riha has a great article on this: How to add hyperlink in the ‘Create HTML table’ Power Automate action (tomriha.com)