VB.net Crystal报表导出为html并使用outlook作为html邮件正文发送

VB.net Crystal报表导出为html并使用outlook作为html邮件正文发送,vb.net,outlook,crystal-reports,export-to-html,Vb.net,Outlook,Crystal Reports,Export To Html,我正在尝试使用outlook应用程序将crystal报告的内容作为电子邮件正文发送。 这是我在VB.net中的代码 Imports outlook = Microsoft.Office.Interop.Outlook Dim a As String = something.ConnectionString Dim cryRpt As ReportDocument Dim username As String = a.Split("=")(3).Sp

我正在尝试使用outlook应用程序将crystal报告的内容作为电子邮件正文发送。 这是我在VB.net中的代码

Imports outlook = Microsoft.Office.Interop.Outlook
Dim a As String = something.ConnectionString
            Dim cryRpt As ReportDocument
            Dim username As String = a.Split("=")(3).Split(";")(0) 'get username
            Dim password As String = a.Split("=")(4).Split(";")(0) 'get password
            cryRpt = New ReportDocument()
            Dim Path As String = Application.StartupPath
            Dim svPath As String = Application.StartupPath & "\PDF"
            If Not Directory.Exists(svPath) Then
                Directory.CreateDirectory(svPath)
            End If
            cryRpt.Load(Path & "\Reports\dr.rpt")
            CrystalReportViewer1.ReportSource = cryRpt
            cryRpt.SetDatabaseLogon(username, password)
            CrystalReportViewer1.Refresh()
            Dim myExportOptions As ExportOptions
            myExportOptions = cryRpt.ExportOptions
            myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
            myExportOptions.ExportFormatType = ExportFormatType.HTML40 'i tried HTML32 also
            Dim html40FormatOptions As HTMLFormatOptions = New HTMLFormatOptions()
            html40FormatOptions.HTMLBaseFolderName = svPath
            html40FormatOptions.HTMLFileName = "dr.htm"
            html40FormatOptions.HTMLEnableSeparatedPages = False
            html40FormatOptions.HTMLHasPageNavigator = False
            html40FormatOptions.UsePageRange = False
            myExportOptions.FormatOptions = html40FormatOptions
            cryRpt.Export()

    Try
                Dim oApp As outlook.Application
                oApp = New outlook.Application

                Dim oMsg As outlook.MailItem
                oMsg = oApp.CreateItem(outlook.OlItemType.olMailItem)

                oMsg.Subject = txtSubject.Text
                oMsg.BodyFormat = outlook.OlBodyFormat.olFormatHTML
                 oMsg.HTMLBody = ""

                oMsg.HTMLBody = getFileAsString(svPath & "\PoPrt\QuotPrt.html")

                oMsg.To = txtEmailId.Text
                Dim ccArray As New List(Of String)({txtCC1.Text, txtCC2.Text, txtCC3.Text})
                Dim cclis As String = String.Join(",", ccArray.Where(Function(ss) Not String.IsNullOrEmpty(ss)))
                oMsg.CC = cclis
                oMsg.Display(True)
            Catch ex As Exception
                MsgBox("Something went wrong", vbExclamation)
            End Try
            SvFormPanel3.Visible = False
功能

Private Function getFileAsString(ByVal file As String) As String
        Dim reader As System.IO.FileStream
        Try
            reader = New System.IO.FileStream(file, IO.FileMode.Open)
        Catch e As Exception
            MsgBox("Something went wrong. " + e.Message, vbInformation)
        End Try

        Dim resultString As String = ""
        Dim b(1024) As Byte
        Dim temp As UTF8Encoding = New UTF8Encoding(True)

        Do While reader.Read(b, 0, b.Length) > 0
            resultString = resultString & temp.GetString(b)
            Array.Clear(b, 0, b.Length)
        Loop

        reader.Close()
        Return resultString
    End Function
报告将以html格式导出到指定位置。当我们手动打开html文件时,它会完美地显示边界线和所有内容。 但是当它被添加为outlook应用程序的html主体时,格式就会消失,看起来很分散。 有人能帮忙吗你试过这个吗

打开outlook,转到,文件>选项>邮件

转到MessageFormat部分并取消选中“通过删除格式减少邮件大小…”


我已经解决了这个问题,将其导出为PDF格式,然后转换为图像并嵌入电子邮件正文。

是的,我也尝试过。。我知道问题是CSS生成的。当我尝试时,效果很好。我们有没有类似的解决方案使我们的html和css邮件客户端友好