当前位置: 代码迷 >> .NET报表 >> reportviewer禁止导出Excel旋钮,
  详细解决方案

reportviewer禁止导出Excel旋钮,

热度:290   发布时间:2016-05-05 01:36:39.0
reportviewer禁止导出Excel按钮,急~~~~~~~~~~
软件使用的是RDLC报表

最近客户说希望软件只能导出pdf

在网上搜了禁止导excel的方法,如下


foreach (RenderingExtension re in rw.LocalReport.ListRenderingExtensions())
{
            //屏蔽掉你需要取消的导出功能 Excel PDF WORD  
      if (re.Name == "Excel")//屏蔽掉Excel PDF WORD类似
     {
            FieldInfo fi = re.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
            fi.SetValue(re, false);
      }
}


我用这个代码发现fi为null,所以抛出未将对象引用到实例的异常

谁知道这是怎么回事吗??? 或者还有别的方法吗 ?
------解决思路----------------------
你就自己做个导出按妞吧,把人家的按钮全都去掉。
------解决思路----------------------
引用:
终于搞定了,感谢google,还是英文搜索好啊
分享代码如下:


            foreach (Microsoft.Reporting.WinForms.RenderingExtension re in this.reportViewer.LocalReport.ListRenderingExtensions())
            {
                if (re.Name == "Excel")\\EXCEL、PDF类似操作
                {
                    FieldInfo fi = re.GetType().GetField("m_serverExtension", BindingFlags.Instance 
------解决思路----------------------
 BindingFlags.NonPublic);
                    if (fi != null)
                    {
                        object actualExtension = fi.GetValue(re);
                        if (actualExtension != null)
                        {
                            PropertyInfo propInfo = actualExtension.GetType().GetProperty("Visible");
                            if (propInfo != null && propInfo.CanWrite)
                            {
                                propInfo.SetValue(actualExtension, false, null);
                            }
                        }
                    }
                }
            }


散分啊啊啊啊啊, 顶贴者有份~~~~~~


谢谢分享
------解决思路----------------------
  相关解决方案