After some research, I managed to find a solution :) The idea is to intercept the ReportViewer "Export Report" function and then start your own process. This process will get the result that the Excel file generates, and then read it and apply all the necessary changes and save it before it is sent as a Download to User. However, it should be noted that the interception method will differ depending on what type of reporting we use. In my case, my ReportViewer uses WebForm instead of WinForm, and most of the explanations explain the ReportExport event, available only in WinForm.
For those using WinForm, you can override the ReportExport event as follows:
void reportViewer_ReportExport(object sender, Microsoft.Reporting.WinForms.ReportExportEventArgs e) { e.Cancel = true;
There is no ReportExport event handler in WebForm. The options I can think of create a custom button in .aspx that will execute our custom code or directly display Excel without having to preview the report. I decided to transfer the excel file directly. I will use the data set and get the data from the stored procedure. Then I assign the dataset to the RDLC and call the Render method to get the result. The output format is in byte [], and I use FileStream to write it. After that I open the Excel file with Interop and apply protection. Here is the code:
Using this concept, I can easily generate report output, since I use RDLC as a template to populate the data provided by the SP, and then visualize it. Imagine the problem if we manually copy the report using Excel (set boundaries, change cells, groupings).
source share