Formatting HTML Tables in Flow

Awhile back I wrote a blog on how to get events from SharePoint and post the events for the day to a Teams Channel. If you’re interested in learning more you can reference that blog here: https://powerusers.microsoft.com/t5/Microsoft-Flow-Community-Blog/Get-SharePoint-Calendar-Events-and-Post-to-Teams/bc-p/324496#M649

The example in the blog utilizes the “Create an HTML Table” action in Flow to output the events results from SharePoint into a nice table format that you can then share in Teams. I got some good feedback that the HTML table which Flow produces leaves a lot to be desired. Many asked how you can add your own styles to that table. In this post, you’ll see the steps needed to apply styles to your HTML Tables in Flow.

Default Behavior

Before we go through how to style your tables, let’s take a look at how the table comes across by default before any styling is applied. If you follow the blog post referenced above, this is the output you would see in your Teams channel.

Figure 1 – Default Table Behavior in Flow

As you can see above, the table doesn’t have any borders and the text is smooshed together which probably isn’t ideal.

Adding Table Borders

As a first step for styling the table, let’s take a look at how we can add in a border around the table and cells to help break out the information. To do this, you’ll need to insert a Compose Action after your Create HTML Table action.

Figure 2 – Adding a Compose Action to insert a table border

You can use the Replace() expression in Flow to take the table and replace the reference to the table object to include a style. Here’s the expression that you will need to put in your new Compose Action for this:

replace(body(‘Create_HTML_table’),'<table>’,'<table border=”1″>’)

That expression will add a 1px border around the table object making the outputted table result look like this:

Figure 3 – Table output with border

That’s a little better, but the data is still smooshed together so you probably want to add some padding.

Adding Padding

To add some space between the text in your table cells, you can insert another Compose Action after the one you just created. You can use the Replace() function again but this time, point it to the Output from your Compose.

Figure 4 – Add Compose action to insert padding

The expression needed to add in spacing on the table rows looks like this:

replace(outputs(‘FormatTable’),'<td>’,'<td style=”padding:20px”>’)

This will put a 20px space all around the row text but you can change that value to be as big or small as you’d like. Now you’ll have a nicely formatted table with spacing!

Figure 5 – Table with padding applied

You can keep repeating this same pattern of Compose actions to replace different objects of the table and insert your own styles.

26 thoughts on “Formatting HTML Tables in Flow”

  1. Excellent.
    The characters ‘ and ” in the code are not copied well, have to change them manually.
    But the overall it works great.

  2. Mads Rosendahl Gunne

    Hi April, I have an alternative approach. You can create a “Data: Composer” named e.g. “Mail Introduction that includes CSS directives. Works fine! Example:

    table, th, td { border: 1px solid black; padding:10px; }

    Attention
    Important stuff below

    Then you just concatenate the intro with your “Create HTML Table” output in another “Data:Composer” and voila. I tested and it works fine.

  3. I get this message when using the code to add padding.
    The template validation failed: ‘The action(s) ‘FormatTable’ referenced by ‘inputs’ in action ‘Compose_2′ are not defined in the template.’.

  4. I’m getting the following error when using the formula to add padding.
    The template validation failed: ‘The action(s) ‘FormatTable’ referenced by ‘inputs’ in action ‘Compose_2′ are not defined in the template.’.

  5. Hi April. This is a fantastic guide and I’ve Incorporated it into several flows. Do you have any tips on conditional formatting of cells in the table based on the cell values? Specifically, if like to change the cell fill color based on a numeric range that the cell values will fall into.

  6. Hi April,
    Thanks for you contribution.
    However, after inserting the function Replace() I didn’t get what you said. The output of the function deleted the structure of the table and didn’t add any lines. Could you please give me hand?

  7. Hi, can you tell us where to find another kinds of this formats? i mean i want to know the expression for give color to headers or indent some text , something like that.
    Thanks

  8. Hi April, is there a way to display line breaks inside the cell of the HTML table. I am pulling in dynamic content. My SP column is multi-line and plain text and It displays correctly in my PowerApps form when editing. It is only when I am creating the outlook calendar event that it displays as one line.

    Here is a snippit:

    Day 4 Schedule: 
     @{body(‘Get_item’)?[‘Day_x0020_4_x0020_Schedule’]}

  9. Excellent , its really helped me a lot but still i have few query can you help me with that

    **********************

    I have requirement

    – I have excel spread sheet on share point which we update everyday based on execution
    – And we have send every day email with Updated table (Table has be there in email body with all values and back ground color of shells )

    I did so far

    – I created Recurrence>> List rows present in a table ( to locate my Excel from share point and get the value of table)>>Select (to map the value with column)>> Create HTML table > compose to give border >Send email

    Problem is that –

    I can see the value in table format but back ground color of particular shell is not coming as per excel sheet , I want background color should also come as per excel sheet which change everyday.

  10. HI,
    However, after inserting the function Replace() I didn’t get what you said. The output of the function deleted the structure of the table and didn’t add any lines. Could you please give me hand?

  11. Hi april,

    Brilliant, this worked straight away for me. I typed it in as I noticed the formatting was a little off on this page as Daniel said but still extremely helpful in making my email look more organised. Thankyou

  12. Manjunath Siddappa

    Awesome!

    However i extended your code. We can simply put css inline style. Hope it will help some one.

    replace(body(‘Create_HTML_table’),”,”)

  13. Hi April. This is Vikram here. Have been following your videos on sharepoint and power automate. Thank you for such great content . I have a query on the html table creation. Is there a way to create a dynamic html table based on the unique mail id value . i.e. is there a way to create an HTML table based out of a sharepoint list or excel table which is triggered as a mail not as a common list but only pertaining to the person/mail id concerned to those rows of data…Looking forward to your suggestion .Thank you in advance.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top