【问题标题】:Export multiple rdlc reports into single word document将多个 rdlc 报告导出为单个 word 文档
【发布时间】:2012-08-01 19:40:41
【问题描述】:

.net 中的报表查看器具有出色的内置导出功能,支持不同的导出格式,如 word、pdf 和 excel。但是,对于我的 asp 应用程序中的管理人员,我希望此导出功能能够生成包含多个 rdlc 报告的单个导出文件,以便他们可以浮动单个文档并继续喝咖啡!。需要导出的报表是根据一些业务逻辑动态决定的。
我在论坛上找到了一个有用的代码 sn-p 来实现这一点,看起来不错:

    protected void ExportReportsToWord(object Sender, EventArgs e)
    {
        // Variables
        Warning[] warnings;
        string[] streamIds;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;

        // reportViewer1 and reportViewer2 are reports on my asp.net page
        byte[] bytes1 = reportViewer1.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
        byte[] bytes2 = reportViewer2.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

        //create a single byte array out of multiple arrays
        byte[] bytes = (bytes2.Concat(bytes1)).ToArray();

        // Now that you have all the bytes representing the Word report, buffer it and send it to the client.
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + "singleReport" + "." + extension);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush(); // send it to the client to download
        Response.End();

    }

此代码符合要求,但使用此代码导出的文件在打开 word 文档时仍仅显示 1 个报告,即使较大的文件大小表明数据可能也在其中用于其他报告。
有人可以指出可能是什么问题吗?如果它可以从多个 rdlc 报告中生成单个单词文件导出,我也愿意接受有关使用完全不同方法的建议。

【问题讨论】:

    标签: c# asp.net .net rdlc export-to-word


    【解决方案1】:

    一个简单的解决方案是创建一个大型主报告。

    在每个元素内都有一个列表,其中的一个子报告。

    将参数传递给主报告以决定显示哪些报告,以及隐藏哪些报告。

    这样,用户可以选择他想查看的报告,并且您可以获得 SSRS 为标准报告提供的所有功能。

    【讨论】:

    • 看起来很有趣,你能给我一些链接/教程吗?我只是想知道隐藏报告是否仍然需要时间来创建,或者它会被 SSRS 忽略。
    • 我没有关于处理时间的任何基准。但请查看此示例以获取子报告:codeproject.com/Articles/195017/…
    【解决方案2】:

    您好,我建议您创建一份报告,其中包含所有这些报告作为子报告,然后安排该主要报告作为 Word 文档作为电子邮件发送给您的老板。

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      相关资源
      最近更新 更多