cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Arslan123
Frequent Visitor

.htm to .csv file conversion

Hello all,

 

I receive a weekly email containing an attachment which is in a .htm format, and I'd like to convert this into a .csv or .xlsx file with Power Automate, does anyone know how I can go about this?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
powercorner
Super User
Super User

Okay I try to make an example.

Lets assume your html looks like this:

 

<!DOCTYPE html>
<html>
<body>
<h2>HTML Tables</h2>

<table id="myTable">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>

</table>

<table id="anotherTable">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>

</table>


</body>
</html>

 

Then I start splitting the information out of the html like that:

 

First I split out my tables ID and I know that my result is on the "right side" of my splitted string. So in the next compose I use the output of the previous compose (but the [1] array field).

Then I split the table finish tag out. And I know that all my info is inside my new array field [0].

So I split out the tablerows (<tr>) next. 

 

Now you have an array with each "csv line"

you just need to replace the <tr> and <th> tags with semicolons (";") for each row.

And then write back the info line by line into a variable or whatever. 

Then you can use the variable as content of a excel file. 

 

powercorner_0-1621801312186.png

 

I hope you understand this approach.


With regards,

Kevin

 

 

View solution in original post

11 REPLIES 11
NiloferA
Super User
Super User

Hello @Arslan123 ,

Perhaps the below post can help you gain some insights.

https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/HTML-Table-to-CSV-or-Pipe-delimited-text...

In case if you have any further queries, I would be happy to answer them!

Please give a Kudo if you found this helpful or Mark this Reply as Solution if it solved your problem.

powercorner
Super User
Super User

Hello @Arslan123 ,

 

making a html to a csv does not sound possible. Is there any table inside the htm file?

If so you could first store the html text inside a variable and then use the "split" Expression to get the values out of the html. Maybe you could send us an example html file so we could help you a little bit with the splitting logic.

 

With regards

Kevin

Hi @NiloferA , thanks for your reply! I can't seem to see the individual steps properly, and I don't have access to Power Automate Desktop. Would you be able to share each step in the flow in that article please if possible?

Hi @powercorner , thanks for your reply! I am unable to attach a .htm file here unfortunately, but have taken a screenshot of a sample one below, hope that helps. There are 3 grey tables at the top, but I am looking to extract the orange table in particular into a csv file. 

 

Arslan123_0-1621798275637.png

 

In the link of @NiloferA there is a zip. You can just import the file to your Power Automate Platform.

powercorner
Super User
Super User

Okay I try to make an example.

Lets assume your html looks like this:

 

<!DOCTYPE html>
<html>
<body>
<h2>HTML Tables</h2>

<table id="myTable">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>

</table>

<table id="anotherTable">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>

</table>


</body>
</html>

 

Then I start splitting the information out of the html like that:

 

First I split out my tables ID and I know that my result is on the "right side" of my splitted string. So in the next compose I use the output of the previous compose (but the [1] array field).

Then I split the table finish tag out. And I know that all my info is inside my new array field [0].

So I split out the tablerows (<tr>) next. 

 

Now you have an array with each "csv line"

you just need to replace the <tr> and <th> tags with semicolons (";") for each row.

And then write back the info line by line into a variable or whatever. 

Then you can use the variable as content of a excel file. 

 

powercorner_0-1621801312186.png

 

I hope you understand this approach.


With regards,

Kevin

 

 

View solution in original post

Thanks @powercorner , I am receiving the .htm file in an email attachment, but i'm struggling to get the flow to open and read the attachment content as HTML in a similar way you have shown above. Instead my output is a Base64 string. Please could you help with this?

 

Arslan123_1-1622209912805.png

 

Hello @Arslan123 ,

 

of course I can help you. (Kudoe and Solution welcome!)

 

If you have a base64 string you can easily compose it like this:

powercorner_0-1622304502451.pngpowercorner_1-1622304540006.png

This is the expression I use:

base64ToString(outputs('Get_file_content')?['body']?['$content'])

and this compose makes my html readable:

powercorner_2-1622304623783.png

 

 

With regards

Kevin

Thanks @powercorner this worked great!

I have used the approach used here to extract the table I need from the .htm file: HTML Table to CSV or Pipe delimited text file - Power Platform Community (microsoft.com)

My table is now in a pipe-delimeted format in a compose action step. Please could you advise how I can now take this data and insert it into a new excel file (as a table)? 

I need this to be in an excel table as I would like to set up the flow to send an email to each individual in the table, so it will go row-by-row and send an email to each individual.

 

Thank you very much for your help so far!

powercorner
Super User
Super User

hey @Arslan123,

 

you could really like my answer at least (otherwise this will be my last answer)  😉

 

well if you want to build an excel file you should create an template file somewhere in your sharepoint. Add one table inside the template excel file and then use this file to create your rows in the flow.  

powercorner_0-1622740084466.png

You can use your info from the csv file and add it row by row to the table.

After you have done that you could move, copy, save or send the file somewhere.

Did you mean this?


With regards
Kevin

Thanks very much for your help with this @powercorner 

i see what you mean, I’ve now set up an excel template but I’m struggling to  get flow to add the data from the csv table to the excel table row by row as you’ve advised, could you guide me through this please?

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,313)