【发布时间】:2016-01-08 16:15:02
【问题描述】:
我的报告在 Reporting Services 服务器中,在我的 .rdl 中有一个接受参数的查询。我使用 ReportViewer 的实例传递这些参数。我有一种方法可以下载 Excel 格式的报告结果,而无需直接使用 ReportViewer。方法如下:
private void CreateEXCEL(Dictionary<string, string> parametros, string nombreReporte)
{
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
string ReportServerURL = ConfigurationManager.AppSettings["ReportServerCompletitudURL"];
string ReportName = ConfigurationManager.AppSettings["ReportNameRankingVentaPDV"] + "/" + nombreReporte;
MyReportViewer.Reset();
MyReportViewer.ProcessingMode = ProcessingMode.Remote;
MyReportViewer.ServerReport.ReportPath = ReportName;
MyReportViewer.ServerReport.ReportServerUrl = new Uri(ReportServerURL);
List<ReportParameter> parameters = new List<ReportParameter>();
foreach (var d in parametros)
{
parameters.Add(new ReportParameter(d.Key, d.Value));
}
MyReportViewer.ServerReport.SetParameters(parameters);
byte[] bytes = MyReportViewer.ServerReport.Render("EXCEL", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + nombreReporte + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
现在的想法是,我不能将超过 65536 行的文件创建为 Excel 文件,想法是“询问”报表中的查询结果是否会产生超过 65k 行,然后使用.csv 格式。 我没有看到 reportviewer 服务器控件具有检查查询结果的方法。 我不想在 SSRS 报告中使用分页符。有什么办法可以在我的代码后面问吗?
【问题讨论】:
标签: c# asp.net excel ssrs-2008-r2