使用vb.net

时间:2015-07-10 19:23:35

标签: html asp.net vb.net rdlc

好的,我的网站使用RDLC生成了数千个PDF,但我的问题有时候我想通过电子邮件发送,但我不想将PDF附加到电子邮件中。所以我需要的是一种生成报告的方法,然后将其转换为文本或html,以便我可以将其作为电子邮件的正文发送。

我也在使用reportviewr版本11

此外,我已经尝试将其导出为.doc然后尝试将其转换为文本,我试图将其导出到excel文档,然后尝试转换它,但没有一个工作。

    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

1 个答案:

答案 0 :(得分:1)

好的,所以我通过一些关于字节的研究解决了我自己的问题。

以下是我用来解决问题的代码。

我所做的是将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

此解决方案并非适合所有人,但它适用于我需要它做的事情。