【问题标题】:How to export report to .xls file from Microsoft.Reporting.WinForms.ReportViewer v11如何从 Microsoft.Reporting.WinForms.ReportViewer v11 将报告导出到 .xls 文件
【发布时间】:2015-10-09 10:46:47
【问题描述】:

请告诉我,如何将报告 (rdlc) 从 ReportViewer (v.11) 导出到 .xls 文件?

此版本的查看器可以通过单击导出 -> Excel 按钮导出到 .xlsx 文件。在这种情况下 SaveFileDialog 将打开,我只能选择 xlsx 格式。但我也需要以 .xls 格式保存报告。

对不起我的英语 - 我刚开始学。

谢谢!

【问题讨论】:

    标签: c# excel winforms reporting


    【解决方案1】:

    我找到了答案。我把它放在这里另一个......

    第 11 版的 ReportViewer 可以将报告导出为 .xls 格式,但默认情况下,这种可能性是隐藏的。

    您可以使用ReportViewer.LocalReport.ListRenderingExtensions() 实例方法查看支持导出格式的数组。但是接收到的元素的所有属性都是只读的(包括Visible)。

    要更改元素的可见性,您应该使用反射。例如:

    /// <summary>
    /// Set visibility of specified by name RenderingExtension to setted value
    /// For example, name of Excel (.xls) extension is "Excel"
    /// </summary>
    /// <param name="reportViewer">Instance of ReportViewer control</param>
    /// <param name="extensionName">Extension name (for example: "Excel")</param>
    /// <param name="visible">Visibility</param>
    private void SetVisibilityOnRenderingExtension(ReportViewer reportViewer, string extensionName, bool visible)
    {
        var renderingExtension = reportViewer.LocalReport.ListRenderingExtensions().FirstOrDefault(e => e.Name == extensionName);
    
        if (renderingExtension != null)
        {
            FieldInfo info = renderingExtension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
            if (info != null)
            {
                info.SetValue(renderingExtension, visible);
            }
        }
    }
    

    我希望,它可以帮助某人:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多