【问题标题】:SSRS - Sending Excel attachment & Body in htmlSSRS - 在 html 中发送 Excel 附件和正文
【发布时间】:2014-02-04 09:30:21
【问题描述】:

我有 2 个数据集:

  • 以 Excel 附件形式发送电子邮件 -- 详细信息
  • 电子邮件正文中的 HTML 格式摘要 -- 第一个结果集的摘要计数

我们如何在 SSRS 中做到这一点?目前我在一个 excel 和 1 个电子邮件中使用 2 个结果集。但我想将电子邮件作为电子邮件正文中的摘要数据集 2 redult 发送,并将结果集 1 作为 Excel 附件发送。

【问题讨论】:

  • 请澄清。我不知道我在读什么。

标签: sql-server-2008 reporting-services rendering subscription


【解决方案1】:

我认为您将不得不为此编写一些代码,因为我认为 SSRS 调度程序不够灵活,无法满足您的需求。我不使用调度程序,我编写了一个程序,它的工作方式与您在此处描述的方式相当。

首先,您要创建一个 HTML 电子邮件:

MailMessage message = new MailMessage("me@mycompany.com", "you@mycompany.com");
message.Subject = "Here is your report!";
message.IsBodyHtml = true;

现在,对于电子邮件的正文,您需要 run the report using the ReportExecutionService.Render method。首先运行呈现为 HTML 的摘要报告,并将其作为电子邮件的消息正文。

message.Body = SummaryReport; // SummaryReport being the HTML report rendered above

接下来,使用ReportExecutionService.Render 方法将详细报告呈现为 Excel 并将其作为附件添加到您的电子邮件:

ms.Seek(0, SeekOrigin.Begin);                          // ms is the MemoryStream that the report rendered to
message.Attachments.Add(new Attachment(ms, filename)); // filename is the name you want the attachment to have in the email

然后发送就完成了!

SmtpClient smtp = new SmtpClient("smtpserver.mycompany.com");
smtp.Send(message);

我没有尝试过的一点是使用摘要报告的 HTML 输出作为电子邮件的正文,但它应该可以工作。我所做的是运行 Sql 以返回摘要并简单地将其手动格式化为 HTML 以创建电子邮件正文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 2012-04-12
    • 2014-10-29
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    相关资源
    最近更新 更多