ReportViewer - Hide PDF Export

前端 未结 18 1686
暖寄归人
暖寄归人 2020-12-13 10:40

I make use of a ReportView component in a VB.Net 2005 app. How can I disable the PDF export functionality, only keeping the MS Excel format?

18条回答
  •  甜味超标
    2020-12-13 11:03

    public void DisableUnwantedExportFormats()
    {
        FieldInfo info;
    
        foreach (RenderingExtension extension in reportViewer.ServerReport.ListRenderingExtensions())
        {
            if (extension.Name != "PDF" && extension.Name != "EXCEL") // only PDF and Excel - remove the other options
            {
                info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                info.SetValue(extension, false);
            }
    
            if (extension.Name == "EXCEL") // change "Excel" name on the list to "Excel 97-2003 Workbook"
            {
                info = extension.GetType().GetField("m_localizedName", BindingFlags.Instance | BindingFlags.NonPublic);
                if (info != null) info.SetValue(extension, "Excel 97-2003 Workbook");
            }
        }
    }
    

    I've tried by adding above said method DisableUnwantedExportFormats() for hiding Export to Excel option. When report loaded first time the Excel option not getting visible.

    However, When I used to call the same method inside of Drillthrough() event "Excel" & PDF option getting visible in Export controls dropdown. I've tried by calling your method in the first statement of my Drillthrough() event (like what I used in Page load method).

    Please let me know, How can I hide the excel option in Drillthrough() event of Reportviewer.

提交回复
热议问题