用rdlc文件隐藏导出excel或PDF格式

rdlc在设计时,如果要将导出格式隐藏,使用下面的方法

protected void ReportViewer1_PreRender(object sender, EventArgs e)

   {

       //ReportViewer rw = sender as ReportViewer;

       //if (rw == null)

       //{

       //    return;

       //}



       //var renders = from r in rw.LocalReport.ListRenderingExtensions()

       //              where string.Compare(r.Name, "Excel", true) != 0

       //              select r;

       //foreach (var r in renders)

       //{

       //    //HideRender(r);

       //}

       foreach (RenderingExtension extension in ReportViewer1.LocalReport.ListRenderingExtensions())

       {

           if (extension.Name == "PDF")

           {

               //extension.Visible = false; // Property is readonly...

               FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);

               fi.SetValue(extension, false);

           }

       }

   }

 

在vs2008中测试通过

你可能感兴趣的:(导出Excel)