ReportViewer - 隐藏PDF导出

19 asp.net reportviewer reporting-services

我在VB.Net 2005应用程序中使用了ReportView组件.如何禁用PDF导出功能,仅保留MS Excel格式?

MMa*_*lke 29

我有完全相同的问题,并使用下面的C#方法解决,在这里找到!:

public void DisableUnwantedExportFormat(ReportViewer ReportViewerID, string strFormatName)
{
    FieldInfo info;

    foreach (RenderingExtension extension in ReportViewerID.LocalReport.ListRenderingExtensions())
     {
        if (extension.Name == strFormatName)
        {
             info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
            info.SetValue(extension, false);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并在page_load上:

DisableUnwantedExportFormat(ReportViewer1, "PDF");
Run Code Online (Sandbox Code Playgroud)


ric*_*ott 10

这是禁用导出选项的方法,只需将Excel以外的所有选项标记为false即可.
*不要忘记重新启动Reporting Services服务.

文件:InstallPath\Reporting Services\ReportServer\rsreportserver.config

启用:

<Extension Name="EXCEL"
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"/>
Run Code Online (Sandbox Code Playgroud)

禁用:

<Extension Name="EXCEL"
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"
Visible="false"/>
Run Code Online (Sandbox Code Playgroud)


jab*_*its 10

这个简单的jQuery方法对我有用:

 $(document).ready(function () {
     $("a[title='PDF']").parent().hide();  // Remove from export dropdown.
     $("a[title='MHTML (web archive)']").parent().hide();  
     $("a[title='TIFF file']").parent().hide();  
 });
Run Code Online (Sandbox Code Playgroud)


小智 5

使用上面的乔恩代码作为参考,我设法在运行时在程序中隐藏“ Excel”。但是,我不是一个很好的VB.net,因此我将示例放在C#中。对此感到抱歉,但希望对您有所帮助。还有一件事,该报告嵌入在ASP.net页内。

  // This is the Load event of the reports itself.
  // Call the recursive method.
  protected void ReportViewerResults_Load(object sender, EventArgs e)
  {
    CustomizeRV((System.Web.UI.Control)sender);
  }

  // Patterned from Jon.
  // Traverse all controls/child controls to get the dropdownlist.
  // The first dropdown list is the ZoomGroup, followed by the ExportGroup.
  // We just wanted the ExportGroup.
  // When a dropdownlist is found, create a event handler to be used upon rendering.
  private void CustomizeRV(System.Web.UI.Control reportControl)
  {
    foreach (System.Web.UI.Control childControl in reportControl.Controls)
    {
      if (childControl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
      {
        System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)childControl;
        ddList.PreRender += new EventHandler(ddList_PreRender);
      }
      if (childControl.Controls.Count > 0)
      {
        CustomizeRV(childControl);
      }
    }
  }

  // This is the event handler added from CustomizeRV
  // We just check the object type to get what we needed.
  // Once the dropdownlist is found, we check if it is for the ExportGroup.
  // Meaning, the "Excel" text should exists.
  // Then, just traverse the list and disable the "Excel".
  // When the report is shown, "Excel" will no longer be on the list.
  // You can also do this to "PDF" or if you want to change the text.
  void ddList_PreRender(object sender, EventArgs e)
  {
    if (sender.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
    {
      System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)sender;
      System.Web.UI.WebControls.ListItemCollection listItems = ddList.Items;

      if ((listItems != null) && (listItems.Count > 0) && (listItems.FindByText("Excel") != null))
      {
        foreach (System.Web.UI.WebControls.ListItem list in listItems)
        {
          if (list.Text.Equals("Excel")) 
          {
            list.Enabled = false;
          }
        }
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

我试图将默认项目选择为“ PDF”,但是找不到启用“导出”文本按钮的方法。:-(


jga*_*ant 2

我通过一些修补设法禁用了 PDF 导出按钮。ReportViewer 类没有任何面向公众的函数来禁用“导出到 PDF”工具栏按钮。为此,请查看以下代码:

在 reportViewer 页面的 OnLoad 事件期间调用此函数:

 Private Sub CustomizeRV(ByVal ctrl As Control)
    For Each c As Control In ctrl.Controls
      If TypeOf c Is ToolStrip Then
        Dim ts As ToolStrip = DirectCast(c, ToolStrip)
        For i As Integer = 0 To ts.Items.Count - 1
          If ts.Items(i).Name = "export" Then
            Dim exp As ToolStripDropDownButton = ts.Items(i)
            AddHandler exp.DropDownOpening, AddressOf disableButton
          End If
        Next
      End If
      If c.HasChildren Then
        CustomizeRV(c)
      End If
    Next
  End Sub
Run Code Online (Sandbox Code Playgroud)

我无法在此处设置工具条按钮的 Visible 属性,因为导出选项是在 OnDropDownOpened 时加载的。相反,我添加了一个处理程序来负责在单击工具条下拉菜单时禁用导出选项。处理函数如下:

  Private Sub disableButton(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim btn As ToolStripDropDownButton = DirectCast(sender, ToolStripDropDownButton)
    btn.DropDownItems(1).Visible = False
  End Sub
Run Code Online (Sandbox Code Playgroud)

基本上,在 Onload 中,您将添加一个事件处理程序,以便当单击“导出下拉”按钮时,将运行上述函数 - 使“导出为 PDF”不可见。

该解决方案肯定会起作用,我刚刚完成它的工作。

如果您有任何疑问,请告诉我。