我认为您将不得不为此编写一些代码,因为我认为 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 以创建电子邮件正文。