Hello all,
The expectation is to copy Excel table in attached file (from A column to H column) by rule - same customer name (column B), and paste to outlook email body, send to receiver list (last column in Excel) accordingly.
Thanks for your kindly help!
BR/Handsome
There are no native actions to either filter a data table or to create an HTML table in PAD (which you need to pass a
table to the body of an email). You can do both, but need some processing to do it.
When it comes to filtering a table of data that you get from Excel, there are a few options:
1. You could read all the data, then create a new table, loop through the data and add the relevant rows to your new table. This is the easiest way to do it, but requires the most actions.
2. You could run a SQL query to the Excel file and add the filters as a WHERE clause in the SQL query. This requires certain drivers to be installed on your machine to support SQL queries to Excel. It is not as straightforward, but is more efficient and requires less actions.
Your flow is doable, but there is no native way to filter data tables in PAD currently. So, you will either need to read all of the data from your Excel sheet and then loop through the resulting data table while getting the rows that are relevant to you and adding them to a new table, or use a SQL connection to the Excel file to extract only the relevant rows right away.
However, since you need to convert your table to an HTML table, meaning you would anyhow need to loop through each row to add the relevant HTML tags, I suggest extracting all the data from Excel and then having a filter condition in the part of the flow that creates your HTML table.
To do that, you first need to extract the data from Excel. This is quite simple:
This will result in your data in a variable called %ExcelData% like this:
Here's a snippet for the code to read the file (you can paste this directly into the PAD designer and the actions will be automatically created for you):
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''{directory}\\Test 0629.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
The next step is creating the HTML table. A HTML table is usually set as follows:
<table>
<tr>
<th>header1</th>
<th>header2</th>
...
</tr>
<tr>
<td>value1</td>
<td>value2</td>
...
</tr>
...
</table>
As mentioned, there is no native way to convert a table in PAD into an HTML table. So, you need to loop through your table and create the appropriate variables.
Step one is setting up the headers of your table. They should each be encapsulated in <th> </th> tags that are also within a row that is as a whole encapsulated in <tr> </tr> tags.
The following steps would create a variable that stores your headers:
What it does is it loops through the column headers of your table. They are accessible via either %ExcelData.Columns% (results in a list variable) or %ExcelData.ColumnHeadersRow% (results in a data row variable), adds them to a separate list with the appropriate tags and then joins it to a single string.
Here's the code snippet for this part:
Variables.CreateNewList List=> TableHeaders
LOOP FOREACH CurrentColumnName IN ExcelData.Columns
Variables.AddItemToList Item: $''' <th>%CurrentColumnName%</th>''' List: TableHeaders
END
Text.JoinText.JoinWithDelimiter List: TableHeaders StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableHeaders
SET TableHeaders TO $''' <tr>
%TableHeaders%
</tr>'''
At the end of it all, you will end up with headers that look like this:
When you're done with that, you need to apply a similar approach to your rows. You can loop through the entire data table getting each row. However, since you need every cell to be added as a column value, you will in fact need two nested loops - one for the rows and then for each value within the row. So, the following set of actions will handle the entire table body dynamically, regardless of how many columns and rows you have:
And here's the snippet:
Variables.CreateNewList List=> TableBody
LOOP FOREACH CurrentRow IN ExcelData
Variables.CreateNewList List=> TableRow
LOOP FOREACH CurrentItem IN CurrentRow
Variables.AddItemToList Item: $''' <td>%CurrentItem%</td>''' List: TableRow
END
Text.JoinText.JoinWithDelimiter List: TableRow StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableRow
SET TableRow TO $''' <tr>
%TableRow%
</tr>'''
Variables.AddItemToList Item: TableRow List: TableBody
END
Text.JoinText.JoinWithDelimiter List: TableBody StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableBody
The body will then look like this:
Finally, at the very end, you need to concatenate the headers and the body, and encapsulate them in the <table> </table> tags like so:
I added the border=1 there to add a table border, but you can use all sorts of other HTML styling there, too.
This will result in a table that looks like this:
<table border = 1>
<tr>
<th>type</th>
<th>Customer name</th>
<th>date</th>
<th>curr.</th>
<th>amt.</th>
<th>others</th>
<th>Contract NO.</th>
<th>Category</th>
<th>Reiceiver list</th>
</tr>
<tr>
<td>194301</td>
<td>China telecom Sichuan</td>
<td>20230628</td>
<td>CNY</td>
<td>341461,89</td>
<td>227693</td>
<td></td>
<td></td>
<td>{sanitized}</td>
</tr>
<tr>
<td>194301</td>
<td>China telecom Yunnan</td>
<td>20230627</td>
<td>CNY</td>
<td>323343,39</td>
<td>10TX2500228631</td>
<td></td>
<td></td>
<td>{sanitized}</td>
</tr>
<tr>
<td>194301</td>
<td>China telecom Guangdong</td>
<td>20230628</td>
<td>CNY</td>
<td>24781,24</td>
<td>00110TX2500276281</td>
<td></td>
<td></td>
<td>{sanitized}</td>
</tr>
<tr>
<td>194301</td>
<td>China telecom Sichuan</td>
<td>20230629</td>
<td>CNY</td>
<td>504562,55</td>
<td>2022</td>
<td></td>
<td></td>
<td>{sanitized}</td>
</tr>
</table>
If you put that into an HTML editor, you'll see the output is like this:
Now, to add that to an email message, all you need to do is put the %Table% variable into the body, next to some text depending to your needs. And you need to enable the Body is HTML setting in the Send email action:
This will get you the desired table in the email body.
Also, for the filtering part, you could actually do a filter while adding rows to your HTML table. So, if you want to only include rows that have a specific email address, you could do a condition in the row loop like so:
This will skip all the actions for the specific row if the email address is not what you check for in the condition. I would suggest storing the email in a variable, but for the sake of simplicity, I hardcoded it here (and then removed the actual value to get through the spam filters for this forum).
You can apply the same conditions for other columns, too.
(Note that I included the typo in "Reiceiver list" on purpose as it's also there in your Excel sheet).
Here's a full snippet of the entire flow for you to copy and paste to your designer (including the row filter condition):
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''{directory}\\Test 0629.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
Variables.CreateNewList List=> TableHeaders
LOOP FOREACH CurrentColumnName IN ExcelData.Columns
Variables.AddItemToList Item: $''' <th>%CurrentColumnName%</th>''' List: TableHeaders
END
Text.JoinText.JoinWithDelimiter List: TableHeaders StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableHeaders
SET TableHeaders TO $''' <tr>
%TableHeaders%
</tr>'''
Variables.CreateNewList List=> TableBody
LOOP FOREACH CurrentRow IN ExcelData
IF CurrentRow['Receiver list'] <> $'''{SomeEmail}''' THEN
NEXT LOOP
END
Variables.CreateNewList List=> TableRow
LOOP FOREACH CurrentItem IN CurrentRow
Variables.AddItemToList Item: $''' <td>%CurrentItem%</td>''' List: TableRow
END
Text.JoinText.JoinWithDelimiter List: TableRow StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableRow
SET TableRow TO $''' <tr>
%TableRow%
</tr>'''
Variables.AddItemToList Item: TableRow List: TableBody
END
Text.JoinText.JoinWithDelimiter List: TableBody StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TableBody
SET Table TO $'''<table border = 1>
%TableHeaders%
%TableBody%
</table>'''
Note that you will need to replace {directory} in the Launch Excel action with the actual folder path to where your file is located. You will also need to replace {SomeEmail} in the condition to actually filter for the applicable email address.
If I solved your question, please mark my answer as the solution.
Thank you.
Try using the Power Automate Cloud Flow with connectors
Refer this link : https://www.powertechtips.com/create-html-table-from-array-power-automate/
Store the customer name to a variable and use the variable name to email
Same try out with Excel Table content after read.
Thank you so much, I will have a try!
thanks @Agnius
this post help me a lot .... only sometimes the headers of excel file created, are not completed ... have you any suggestion about?
Can you please elaborate on the issue a bit? What do you mean they are not completed? Maybe you can share some screenshots?
Hi @Agnius
thanks for your reply
this is my excel
and this is my power automate desktop
I write the files in 2 ways: html and excel.
HTML works well but it's too long to execute.
XLSX works but skip the headers ... I try also with a query that retrives the name of columns, but I'm not able to create a datatable with data retrieved from this query:
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'mytable'
any suggestion will be apprecied.
You are using an incorrect value for the headers list in your loop. You should not use %F01QueryResult.ColumnHeadersRow.ColumnNames%. Instead, you should use %F01QueryResult.ColumnHeadersRow% OR %F01QueryResult.ColumnNames%.
Actually, since %F01QueryResult.ColumnHeadersRow% is a datarow, when you write it to Excel, you can simply write the entire row at once without using a loop. Just send it to the first column and it will write the entire header row.
If you use %F01QueryResult.ColumnNames%, you do actually need a loop, because this will result in a list instead of a data row. I would also suggest that instead of writing to the active cell and using keystrokes to navigate, you would simply have a column index starting at 1 and use Increase variable inside your loop to keep increasing it. Then use that column index when writing to Excel.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.
@Agnius please .... can you indcate me an example for:
"I would also suggest that instead of writing to the active cell and using keystrokes to navigate, you would simply have a column index starting at 1 and use Increase variable inside your loop to keep increasing it. Then use that column index when writing to Excel."?
You can do something like this:
Set %ColumnIndex% to 1
For each %F02ExcelInstanceHead% in %F01QueryResult.ColumnNames%
Write %F02ExcelInstanceHead% to Excel at row 1 and column %ColumnIndex%
Increase variable %ColumnIndex% by 1
End loop
This is a generic text interpretation of the actions needed. I think you should be able to reproduce these in PAD.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages