【问题标题】:Is there any way to ask a ReportViewer if the result of the query inside a Report will yield more than 65k rows?有什么方法可以询问 ReportViewer 报告中的查询结果是否会产生超过 65k 行?
【发布时间】: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


    【解决方案1】:

    不确定这是否有帮助,但这是导出到 excel 的一种解决方法。

    在 tablix(或表或列表)上创建父组,并在 Group on: 字段中输入以下表达式。

    在组的每个实例之间添加分页符

    =CInt(Ceiling(RowNumber(nothing)/65000))
    

    Question on Here.

    【讨论】:

    • 你会不会碰巧知道我的“详细信息”组中的这个表达式是否足够?在 Disabled 属性中:=IIF(rownumber(nothing) mod 10000=0,false,true) BreakLocation:End 如果我想在我加载报告的 Microsoft VS 2008 中下载 .xls,它可以工作。但如果我尝试从应用程序下载它,它不会。
    【解决方案2】:

    我找到了解决这个特定问题的方法,如下所示:

    将此表达式放在我的“详细信息”组中。在禁用属性中:=IIF(rownumber(nothing) mod 10000=0,false,true) BreakLocation:End。 进行此更改后,我可以将此 excel 保存在同一个 Excel 表中的不同工作表中,每 10k 行。我试过做天花板,但如果你在那个组中有一个行号表达式,它就不起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多