So this is what I am getting-
An this is the result-
Very Interesting! I could not recreate this on my end. Can you please tell me what version of outlook you are using?
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.
In the body value for the send outlook message activity- lets keep it as out_strBodyContent and see if we have any luck.
It works on my end for either option so I am not sure if this will work for you (but I hope it does!)
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 â<&/span>â)
HTML_output.Replace(ânbsp; lt&/span>â,"Â lt&/span>")
Below is the code attached.
ExcelToEmail.zip (46.7 KB)