[英]How to Compress and Email Excel Report in SSRS(SQL Server Reporting Services) in Run Time?
I am new to SSRS,firstly sorry if this question was already posted,but after fine search i am posting this.我是 SSRS 的新手,如果这个问题已经发布,首先很抱歉,但经过精细搜索我发布了这个。
In my Business Intelligence Development studio i am generating SSRS reports and saving them to excel format,everything works till now.But after this i need to email these reports to the client in the run time which i am unable to do because of larger file size.Till now i did this manually.But i need them to be done in run time.I searched a lot of stuff regarding how to compress and Email the report in run time,but in vain i posted this.在我的商业智能开发工作室中,我正在生成 SSRS 报告并将它们保存为 excel 格式,直到现在一切正常。 .直到现在我都是手动完成的。但是我需要在运行时完成它们。我搜索了很多关于如何在运行时压缩和通过电子邮件发送报告的东西,但我张贴了这个。
Responses with screenshots were appreciated.Thanks in advance.对屏幕截图的回应表示赞赏。提前致谢。
You'll have to do this programmatically - that is, write a program that runs a report, renders it to Excel, saves it, compresses it then emails it out. 您必须以编程方式执行此操作-也就是说,编写一个运行报告的程序,将其呈现到Excel,保存,压缩,然后通过电子邮件发送出去。
It sounds hard but is actually quite simple. 听起来很难,但实际上很简单。 Using the ReportExecutionService.Render
method you can render the report however you want, so you'd render to Excel, compress the output and attach them to emails. 使用ReportExecutionService.Render
方法可以根据需要呈现报表,因此可以呈现到Excel,压缩输出并将其附加到电子邮件。
The MSDN site has some code to get you started . MSDN网站上有一些代码可以帮助您入门 。
Adding a late answer to this in case someone runs into the same scenario.如果有人遇到相同的情况,请为此添加一个迟到的答案。
The way I solved this was to change the SSRS subscription to write to "Windows File Share" instead of email.我解决这个问题的方法是将 SSRS 订阅更改为写入“Windows 文件共享”而不是电子邮件。
This is particularly helpful if your email system has size limits and the file is too large.如果您的电子邮件系统有大小限制并且文件太大,这将特别有用。 Also, emailing Excel in SSRS has a row limit of ~65k, but it does not have this limit for the file system if you select Excel and not Excel 2003 (you do not have this choice with email).此外,在 SSRS 中通过电子邮件发送 Excel 的行限制为 ~65k,但如果您选择 Excel 而不是 Excel 2003(电子邮件没有此选择),则文件系统没有此限制。
Once it is saved on the file system, create a SQL Server job that has two steps:将其保存在文件系统上后,创建一个包含两个步骤的 SQL Server 作业:
Zip the file.压缩文件。 Use xp_cmdshell and 7-Zip like this for example:例如,像这样使用 xp_cmdshell 和 7-Zip:
exec master.dbo.xp_cmdshell '"C:\\Program Files\\7-Zip\\7z.exe" a -tzip C:\\Reports\\MyReports.zip C:\\Reports\\MyReport.xlsx'
Send the zipped file via Database Mail like this example:通过数据库邮件发送压缩文件,如下例所示:
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'SERVER DBMAIL', @recipients = 'email@foo.com', @subject = 'My Report', @file_attachments='C:\\Reports\\MyReport.zip';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.