使用 vb.net 在电子邮件中发送 RDLC
Send RDLC in an email using vb.net
好的,我的网站使用 RDLC 生成了数千个 PDF,但我的问题是有时我想通过电子邮件发送它们,但我不想将 PDF 附加到电子邮件中。所以我需要的是一种生成报告然后将其转换为文本或 html 的方法,以便我可以将其作为电子邮件正文发送。
我也在使用 reportviewr 版本 11
我还尝试将其导出为 .doc,然后尝试将其转换为文本,我尝试将其导出为 excel 文档,然后尝试将其转换为 none作品。
Dim warn() As Warning = Nothing
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim bytes() As Byte
bytes = rv.LocalReport.Render("MHTML", Nothing, mimeType, encoding, extension, streamids, warn)
'Only one copy of the notice is needed
'If Not Directory.Exists(strFilePath) Then Directory.CreateDirectory(strFilePath)
Dim fs As New FileStream(strFilePath, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
这是我正在使用的代码,但它给我一个错误:Specified argument was out of the range of valid values. Parameter name: format
我也知道这段代码有效,因为我使用完全相同的东西将 rdlc 导出为 PDF
好的,我通过一些关于字节的研究解决了我自己的问题。
这是我用来解决问题的代码。
我所做的是将 reportviewr 导出为 word 文档,然后将所有字节转换为文本。然后你会得到一大堆乱码,但最终你会从你的 RDLC 中找到文本。所以我所做的是将字符串拆分到只剩下我的 RDLC 中的措辞的地方。
查看以下代码:
Function GetRDLCText(ByVal rv As ReportViewer) As String
Dim warn() As Warning = Nothing
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim bytes() As Byte
Dim msg() As String
bytes = rv.LocalReport.Render("WORD", Nothing, mimeType, encoding, extension, streamids, warn)
'Word is the only export that contains text from the rdlc
Dim content As String = System.Text.Encoding.Unicode.GetString(bytes)
msg = content.Split("Ù")
msg = msg(1).Split("Ѐ")
Return msg(0)
End Function
这个解决方案并不适合所有人,但它可以满足我的需要。
好的,我的网站使用 RDLC 生成了数千个 PDF,但我的问题是有时我想通过电子邮件发送它们,但我不想将 PDF 附加到电子邮件中。所以我需要的是一种生成报告然后将其转换为文本或 html 的方法,以便我可以将其作为电子邮件正文发送。
我也在使用 reportviewr 版本 11
我还尝试将其导出为 .doc,然后尝试将其转换为文本,我尝试将其导出为 excel 文档,然后尝试将其转换为 none作品。
Dim warn() As Warning = Nothing
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim bytes() As Byte
bytes = rv.LocalReport.Render("MHTML", Nothing, mimeType, encoding, extension, streamids, warn)
'Only one copy of the notice is needed
'If Not Directory.Exists(strFilePath) Then Directory.CreateDirectory(strFilePath)
Dim fs As New FileStream(strFilePath, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
这是我正在使用的代码,但它给我一个错误:Specified argument was out of the range of valid values. Parameter name: format
我也知道这段代码有效,因为我使用完全相同的东西将 rdlc 导出为 PDF
好的,我通过一些关于字节的研究解决了我自己的问题。
这是我用来解决问题的代码。
我所做的是将 reportviewr 导出为 word 文档,然后将所有字节转换为文本。然后你会得到一大堆乱码,但最终你会从你的 RDLC 中找到文本。所以我所做的是将字符串拆分到只剩下我的 RDLC 中的措辞的地方。
查看以下代码:
Function GetRDLCText(ByVal rv As ReportViewer) As String
Dim warn() As Warning = Nothing
Dim streamids() As String = Nothing
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim bytes() As Byte
Dim msg() As String
bytes = rv.LocalReport.Render("WORD", Nothing, mimeType, encoding, extension, streamids, warn)
'Word is the only export that contains text from the rdlc
Dim content As String = System.Text.Encoding.Unicode.GetString(bytes)
msg = content.Split("Ù")
msg = msg(1).Split("Ѐ")
Return msg(0)
End Function
这个解决方案并不适合所有人,但它可以满足我的需要。