SSRS Reporting - Exporting To Excel
I am new to SSRS Reporting 2008 and most of the reports I have developed required to export to Excel. This reports are embedded into ASP.NET, developed in C#. Now there is some questions I would like to ask:
1) When I am exporting to Excel, I would like to insert some comment in the some cells in the Excel (comment like where you see a red dot in each cell in Excel, and when mouse over you can see comment of this cell)
2) Is there anyway to put a filter to the header after export to Excel?
October 13th, 2010 9:07pm
If you are using ASP.NET to physically render the report to excel rather than doing it manually then once you have rendered the report to excel, you should be able to pick up the file and manipulate it using the office interop assemblies. Once you have imported
them into the ASP.NET code you can use something like
Dim XL as new Excel.application
Dim wb as excel.workbook = XL.open(filepath & name)
Dim ws as excel.worksheet = wb.sheets(Sheetname)
ws.autofilter
wb.close(true)
Rgds Geoff
Free Windows Admin Tool Kit Click here and download it now
October 13th, 2010 9:25pm
But I am not using ASP.NET to render the report. What I am doing now is, having the ASP.NET code calling & displaying the reports (which already in .rdl)
Since the report already have option to export to Excel, I do not do much of the exporting code in ASP.NET. Now what I want to know is whether SSRS can do some formatting (like add comment, filtering) to the Excel sheet/cells when I click on export/save
to Excel option from the reports itself.
Thanks. Terence
October 13th, 2010 9:42pm
"what I want to know is whether SSRS can do some formatting (like add comment, filtering) to the Excel sheet/cells when I click on export/save to Excel option from the reports itself."
No - it can't. the export option does exactly what it says on the tin - it renders what is on screen to excel
The only ways I know of to add extra functionality to excel rendered SSRS reports is to either do it manually or programmatically from whatever you use to render the report
If you are using ASP.NET to display the reports then you have access to code in which to run and render the report directly to excel. Once it is saved to a file, you can pretty much do anything to it using C#
Rgds Geoff
Free Windows Admin Tool Kit Click here and download it now
October 13th, 2010 10:31pm
Hmm.. OK. Thanks for the advise. Will try it out! :)
October 14th, 2010 12:15am
No worries - here is a link that should help:
http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx
A bit of hacking should allow you to run your reports programmatically - this also allows you to specify the report destination so you will know wherre the ouput file is - you can then "pick it up" and start customising to your heart's content!!Rgds Geoff
Free Windows Admin Tool Kit Click here and download it now
October 14th, 2010 1:01am
Hello..
I searched so many sites to find "Direct Export to excel from ssrs reports in asp.net c# windows or console application code?" but i did't get the right code and also save the exported excel file in specific folder.. Please provide me best
solution to solve my problem...
Best regards
September 30th, 2012 5:29am
Mani use the following Code;
ReportViewer rv = new ReportViewer();
rv.ServerReport.ReportServerUrl = new Uri(reportServer);
rv.ServerReport.ReportPath = ReportPath;
rvc.ReportServerUrl = rv.ServerReport.ReportServerUrl;
int Counter = 0;
List<ReportParameter> paramList = new List<ReportParameter>();
ReportParameterInfoCollection paramInfo = rv.ServerReport.GetParameters();
ReportParameter[] Param = new ReportParameter[paramInfo.Count];
foreach (ReportParameterInfo Pinfo in paramInfo)
{
string[] arlistDefault = null;
string Pvalue="";
if (Pvalue == "")
{
foreach (string value in Pinfo.Values)
{
Pvalue = Pvalue + "~" + value;
}
}
arlistDefault = Pvalue.Remove(0, 1).Split(new char[] { '~' });
Param[Counter++] = new ReportParameter(Pinfo.Name, arlistDefault);
}
rv.ServerReport.SetParameters(Param);
string SaveLocation = "D:\Test Folder\test.xls";
string mimeType;
string encoding;
string extension;
string[] streams;
Warning[] warnings;
byte[] Bytes = rv.ServerReport.Render("EXCEL", string.Empty, out mimeType, out encoding, out extension, out streams, out warnings);
if (File.Exists(SaveLocation))
{
System.IO.File.Delete(SaveLocation);
}
System.IO.FileStream fs = new System.IO.FileStream(SaveLocation, System.IO.FileMode.Create);
fs.Write(Bytes, 0, Bytes.Length);
fs.Close();
fs.Dispose();
Noman Rao
Free Windows Admin Tool Kit Click here and download it now
November 7th, 2012 11:45pm


