How to write the contents of excel into email message body without loosing table formats

@Mr_Meeseeks

So this is what I am getting-

image

An this is the result-

image

1 Like

@veselim

Can you please attach a copy of the xaml file? I’ll take a look at it.

1 Like

@Mr_Meeseeks

Can Do!

How to write excel data in outlook mail.xaml (21.2 KB)

Thank you!!

3 Likes

@veselim

Very Interesting! I could not recreate this on my end. Can you please tell me what version of outlook you are using?

image

It looks like all of the HTML formatting in “out_strBodyContent” works though! Lets try this: add an assign activity right before the send outlook message activity and to add the body message there.

image

In the body value for the send outlook message activity- lets keep it as out_strBodyContent and see if we have any luck.

image

It works on my end for either option so I am not sure if this will work for you (but I hope it does!)

2 Likes

@Mr_Meeseeks

Yes, the assign worked! Great Job!

Hello
Try this. You can download this package and use the activity.
(UiPath Marketplace | Error)

I have completed this task is 4 stages:

1. Open the excel in excel scope and make it visible. Activate the sheet which you want to send us an email.

2. There is an option to publish the sheet in HTML, which can be achived through VBA code to publish the sheet in HTML.
Below is the VBA function which returns your HTML string of the sheet.

Change the "sheetName " with your “sheetname”

Function SheettoHTML()

Dim fso As Object
Dim ts As Object
Dim TempFile As String

TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".html"

With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
    TempFile, "_sheetName_", ActiveSheet.UsedRange.Address, xlHtmlStatic, _
    "", "")
    .Publish (True)
End With

'WaitAFewSeconds SecondsToWait:=3
Application.wait (Now + TimeValue("0:00:03"))


'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                      "align=left x:publishsource=")


'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing

End Function

3. The above HTML string is generated by Excel publish will have CSS styling according to Microsoft excel publish which won’t work properly in Gmail as Gmail uses open-office lib.
You need to convert the excel published HTML to achive your goal by using premailer.
So I have used package, Premailer.Net 2.4.0 for it. below it the C# code for conversion using invoke code.

//String htmlSource = File.ReadAllText(@“C:\aj\Book1.html”);
var result = PreMailer.Net.PreMailer.MoveCssInline(htmlSource);
res = result.Html;
warnArr = result.Warnings;

Note:
res → datatype = String
warnArr → datatype = List

4. If you are getting the garbage value in report, you can use the below code. (remove the extra code between “nbsp;” and “&lt&/span&gt”)

HTML_output.Replace(“nbsp; lt&/span&gt”," lt&/span&gt")

Below is the code attached.
ExcelToEmail.zip (46.7 KB)