問題描述
將 Crystal Reports 轉換為 HTML 並作為正文發送到我的郵件中 (Crystal Reports into HTML and sending in my mail as body)
我在 VB.NET 中使用 Crystal Report。我想使用 Microsoft Outlook 在郵件中將報告作為正文發送。
我的代碼如下,它將 Crystal Report 轉換為 Outlook 正文部分的 html,但它顯示為 html 標籤。
Private Sub FrmViewReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim mailbodybutton As New ToolStripButton
mailbodybutton.Image = ts.Items(10).Image
ts.Items.Remove(ts.Items(10))
ts.Items.Insert(10, mailbodybutton)
AddHandler ts.Items(10).Click, AddressOf CaptureMailBodyEvent
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub CaptureMailBodyEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyClass.Click
Try
Dim oStream As System.IO.MemoryStream
oStream = objReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.HTML40)
oStream.Position = 0
Dim sr = New System.IO.StreamReader(oStream)
Dim html = sr.ReadToEnd()
Dim app As Microsoft.Office.Interop.Outlook.Application
Dim appNameSpace As Microsoft.Office.Interop.Outlook.NameSpace
Dim memo As Microsoft.Office.Interop.Outlook.MailItem
app = New Microsoft.Office.Interop.Outlook.Application
appNameSpace = app.GetNamespace("MAPI")
appNameSpace.Logon(Nothing, Nothing, False, False)
memo = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
memo.Subject = NVlTrim(m_ReportTitle, "Report")
memo.Body = html
memo.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
memo.Display()
Catch ex As Runtime.InteropServices.COMException
Console.WriteLine(ex.ToString())
End Try
End Sub
它應該顯示為 Crystal Report 而不是 HTML 標籤中的顯示
參考解法
方法 1:
You should Try
memo.HTMLBody = html
(by Danish Siraj、Surensiveaya)