【问题标题】:How to export to excel from a report on SSRS via ReportViewer control如何通过 ReportViewer 控件从 SSRS 报告中导出到 Excel
【发布时间】:2015-10-01 14:53:07
【问题描述】:

也许有人问过这个问题,如果是,请随时为我指出正确的方向。

我有一份关于 SSRS 的报告,我的数据集/数据源当然在那里。数据集是一个动态查询。

这个想法是通过 Excel 导出报告的结果。

我的 Aspx 中有一个 Web 服务器控件 ReportViewer。有谁知道是否有导出到 excel 的方法以及如何在我的代码中对其进行编码。

如果您需要更多信息,请告诉我,我会发布。

编辑: 检查信息和其他链接我做了以下方法。

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;

        List<ReportParameter> parameters = new List<ReportParameter>();

        foreach (var d in parametros)
        {
            parameters.Add(new ReportParameter(d.Key, d.Value));
        }



        // Setup the report viewer object and get the array of bytes
        MyReportViewer.ProcessingMode = ProcessingMode.Remote;
        MyReportViewer.ServerReport.ReportPath = nombreReporte;

        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

    }

但是当我执行我的网络应用程序并调用此方法时,我有以下错误: 服务器犯了协议违规Section=ResponseStatusLine

有人遇到过这样的问题吗?

【问题讨论】:

标签: c# asp.net reporting-services ssrs-2008


【解决方案1】:

你可以使用.Render方法:

MSDN 提供的示例适用于 Excel,但您可以对 PDF 和任何其他支持的格式使用相同的方法。

请注意,也可以使用ReportViewer 的内置功能手动导出到 Excel/PDF。

【讨论】:

    【解决方案2】:

    嗨,伙计,如果您的列在数据集中是动态的,那么 SSRS 中就没有这样的选项。但是我可以给你一个提示,比如当你编辑和 SSRS 时它会喜欢 XML。

    记住这一点,您可以从代码中将数据集的整个结构构建为 RDLC 文件。

    具体来说,您需要在运行时生成 RDLC 文件。使用一些常见的模板并将模板占位符替换为列值的

    我个人向您保证,导出数据不会花费太多时间。但是你应该付出一些努力来实现这一点。 我根据我过去的经验告诉这个解决方案。我做过这样的事情:)

    如果您需要更多信息,请随时询问。但不要问代码。

    【讨论】:

      【解决方案3】:

      服务器违反了协议 Section=ResponseStatusLine

      这是一个可能有帮助的答案: https://stackoverflow.com/a/4289266/3854195

      【讨论】:

        猜你喜欢
        • 2013-01-30
        • 2018-06-19
        • 1970-01-01
        • 2011-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多