【问题标题】:Send RDLC in an email using vb.net使用 vb.net 在电子邮件中发送 RDLC
【发布时间】:2015-07-10 19:23:35
【问题描述】:

好的,我的网站使用 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

【问题讨论】:

  • 为什么不使用作为标准选项的 MHTML 输出?
  • 查看我的编辑。添加了我正在使用的代码和我得到的错误。是不是我做错了什么?
  • 抱歉——我认为本地报告 (RDLC) 肯定会支持与服务器报告 (RDL) 相同的输出格式。遗憾的是,本地报告似乎仅支持以下格式:ExcelPDFWordImage.
  • 我想通了谢谢!
  • 您应该考虑发布您的解决方案作为您自己问题的答案。欢迎使用 Stack Overflow。

标签: html asp.net vb.net rdlc


【解决方案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

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

【讨论】:

    猜你喜欢
    • 2010-12-24
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    相关资源
    最近更新 更多