Skip to main content

Notifications

Community site session details

Community site session details

Session Id : cY6XVPtRnyWLEhOPuG2aR0
Power Apps - Building Power Apps
Answered

convert HTML to word attachment

Like (0) ShareShare
ReportReport
Posted on 17 Mar 2021 17:24:26 by 115

Hi, i have a button able to send the collection data to email

ffice365Outlook.SendEmail("email","Test222",Concatenate("<table style=""width:100%"" border=""1"">
<tr>
<th>BBB</th>
<th>Finding</th>
<th>Rectification</th>
</tr>",Concat(ForAll(FilteredCollection,"
<tr>
<td>"&ThisRecord.No&"</td>
"&"<td>"&Concat(Filter(ForAll(ThisRecord.image,If("before" in ThisRecord.DisplayName,"<img height=""100"" width =""100"" src='"&ThisRecord.AbsoluteUri&"'>")),!IsBlank(Value)),Value)&"</td>"&"<td>"&Concat(Filter(ForAll(ThisRecord.image,If("after" in ThisRecord.DisplayName,"<img height=""100"" width =""100"" src='"&ThisRecord.AbsoluteUri&"'>")),!IsBlank(Value)),Value)&"</td>"&"
</tr>
"),Value),"</table>"),{IsHtml: true })

Email Received

pityman_0-1616001713958.png

Now the question is, is it possible to convert it to a word file? Meaning that when i click on the button, i will be able to see the table in the email as well as the word attachment which also consist of the table ?

Thank you

 

Categories:
  • Verified answer
    Pstork1 Profile Picture
    66,154 Most Valuable Professional on 20 Mar 2021 at 16:33:30
    Re: convert HTML to word attachment

    Here is an example. I created an app that has a small collection called 'myData' containing the path to an image in onedrive, the relative path to the image, and the name of the file. 

    image.png

    When you press the button it invokes a flow and passes the collection to the flow as a JSON array using the following 

    HTML2PDF.Run(JSON(myData,JSONFormat.Compact))

     The flow then processes the collection.  Here are screenshots of the flow.

    The array is passed in as the only parameter and processed using a Parse JSON action

    image.png

    I then create two string Variables, one to hold the top of the HTML file and one to hold the bottom.

    image.png

    Next I create a loop to process the JSON array loaded earlier.  Inside the loop I use the relative path to retrieve the image contents, A compose to translate the contents to DataURI encoding, and then append the converted image and name to the header string variable as an HTML row.  The loop processes each image.

    image.png

    once the loop exits I append the html footer variable to close out the HTML.  Then I save the HTML file to OneDrive, Convert it to PDF, and then save the Converted file.  (Encodian has a conversion option that can convert from HTML to Word).

    image.png

    Here's what the finished file looks like.

    image.png

  • pityman Profile Picture
    115 on 20 Mar 2021 at 15:04:36
    Re: convert HTML to word attachment

    @Pstork1 

    i am really appreciate if you can show me the example 

  • Pstork1 Profile Picture
    66,154 Most Valuable Professional on 19 Mar 2021 at 12:27:28
    Re: convert HTML to word attachment

    By Collection I assume you mean an array.  If so you would use an Apply to Each loop to loop through the array, retrieve each image and save it to HTML using the dataUri() function.  Inside each loop you would add all the entries to the HTML table for that Row.

  • pityman Profile Picture
    115 on 19 Mar 2021 at 02:00:36
    Re: convert HTML to word attachment

    HI @Pstork1 , yes, there are no issues when get the specific image in sharepoint/one drive and convert into 64images.

    Currently my problem is,

    the images are in a collection. How do i get the content of the images from a collection in powerapps and , process them with the dataUri() function?

  • Pstork1 Profile Picture
    66,154 Most Valuable Professional on 18 Mar 2021 at 13:00:21
    Re: convert HTML to word attachment

    As Shane explained in the video you need to convert the images to files and then insert the contents of the files into the HTML.  You can't just reference the images by URL. You have to get the file content, process it with the dataUri() function and insert the resulting string into the HTML.  Shane does this with a variable at around the 10 minute mark of the video. If you are doing multiple images you can do it with either a variable or a Compose.

  • pityman Profile Picture
    115 on 18 Mar 2021 at 03:54:30
    Re: convert HTML to word attachment

    Hi@Pstork1, i tried to follow the video and the images gone. any idea?

    pityman_0-1616039613470.png

     

  • Pstork1 Profile Picture
    66,154 Most Valuable Professional on 17 Mar 2021 at 17:53:53
    Re: convert HTML to word attachment

    Shane Young has a great video on creating PDFs from HTML. But the convert action he uses can also output to Word format.  So yes the HTML table can be converted to a Word document and then attached to the email using Power Automate.

    PowerApps PDF Generator using Microsoft Flow PDF Converter - Bing video

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 58

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 42 Super User 2025 Season 1

Overall leaderboard
Loading started