简体   繁体   中英

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.

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.

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.

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.

The MSDN site has some code to get you started .

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.

在此处输入图片说明

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).

Once it is saved on the file system, create a SQL Server job that has two steps:

  1. Zip the file. Use xp_cmdshell and 7-Zip like this for example:

    exec master.dbo.xp_cmdshell '"C:\\Program Files\\7-Zip\\7z.exe" a -tzip C:\\Reports\\MyReports.zip C:\\Reports\\MyReport.xlsx'

  1. 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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM