当前位置:编程学习 > C#/ASP.NET >>

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);
                            }
                        }
                    }
                }
            }


散分啊啊啊啊啊, 顶贴者有份~~~~~~ --------------------编程问答-------------------- .
散分啊啊啊啊,顶贴者有份~~~~~

其中这一句中的false就是设置

propInfo.SetValue(actualExtension, false, null)
--------------------编程问答--------------------
引用 2 楼 zuoxxx 的回复:
终于搞定了,感谢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);
                            }
                        }
                    }
                }
            }


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


谢谢分享 --------------------编程问答--------------------
补充:.NET技术 ,  图表区
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,