ReportViewer - Hide PDF Export

前端 未结 18 1622
暖寄归人
暖寄归人 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 10:49

    I had the same problem. I could get the unwanted export options to hide when the report rendered, but it didn't work in the case of a drillthrough report. The following code worked for both the parent and drillthrough reports, using a LocalReport:

        private void SuppressExportButton(ReportViewer rv, string optionToSuppress)
        {
            var reList = rv.LocalReport.ListRenderingExtensions();
            foreach (var re in reList)
            {
                if (re.Name.Trim().ToUpper() == optionToSuppress.Trim().ToUpper()) // Hide the option
                {
                    re.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(re, false);
                }
            }
        }
    

    The trick is to call the method from the page PreRender method:

        protected void Page_PreRender(object sender, System.EventArgs e)
        {
            SuppressExportButton(rvMain, "PDF");
            SuppressExportButton(rvMain, "Word");
        }
    

提交回复
热议问题