2009-09-30 15 views

risposta

2

Sono riuscito a disattivare il pulsante Esporta PDF con qualche ritocco. La classe ReportViewer non ha alcuna funzione pubblica rivolta per disabilitare il pulsante della barra degli strumenti Esporta in PDF. Per farlo, date un'occhiata al seguente codice:

chiamare questa funzione durante l'evento OnLoad della pagina ReportViewer:

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 

non ho potuto impostare la proprietà Visible del pulsante ToolStrip qui , poiché le opzioni di esportazione sono caricate su OnDropDownOpened. Invece, ho aggiunto un gestore che si occupa della disattivazione dell'opzione di esportazione quando si fa clic sul menu a discesa Barra degli strumenti. La funzione di gestione è la seguente:

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 

Quindi, fondamentalmente, onLoad si sta aggiungendo un gestore eventi in modo che quando il pulsante Esporta Drop Down viene cliccato, la funzione di cui sopra verrà eseguito - rendendo l'Esporta in PDF invisibile.

La soluzione funzionerà sicuramente, ho appena finito di farlo funzionare.

Se avete domande, fatemi sapere.

10

In questo modo si disattiva un'opzione di esportazione, è sufficiente contrassegnare tutti quelli eccetto Excel su falso.
* Non dimenticare di riavviare il servizio Reporting Services.

File: installpath \ Reporting Services \ ReportServer \ RSReportServer.config

Attivo:

<Extension Name="EXCEL" 
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"/> 

disabili:

<Extension Name="EXCEL" 
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering" 
Visible="false"/> 
4

Utilizzando il codice del jon sopra come riferimento , Riesco a nascondere "Excel" nel programma in fase di esecuzione. Tuttavia, non sono un buon VB.net quindi ho inserito un esempio in C#. Mi dispiace ma spero che questo aiuti. Un'altra cosa, il report incorporato in una pagina 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; 
      } 
     } 
     } 
    } 
    } 

stavo cercando di selezionare la voce di default su "PDF", ma non riusciva a trovare un modo per attivare il pulsante di testo "Esporta". :-(

+0

funziona come un fascino - grazie! –

0

Dopo 4 ore di ricerca ho trovato la soluzione ho fatto alcuni piccoli cambiamenti al codice del marol di essere più piccolo:

 Control ReportViewerControl = ReportViewer1.FindControl("Ctl01"); 
     Control ExportGroupControl = ReportViewerControl.FindControl("Ctl05"); 
     DropDownList DropDownControl = (DropDownList)ExportGroupControl.FindControl("Ctl00"); 
     DropDownControl.PreRender += new EventHandler(ddList_PreRender); 
1

Se aiuta ... il codice per nascondere l'oggetto di Excel em VB.Net (Net 3,5)

Private Sub CustomizeRV(ByVal ctrl As ReportViewer) 

    For Each c As Control In ctrl.Controls 

     If c.GetType.ToString = "Microsoft.Reporting.WebForms.ToolbarControl" Then 

      For Each ct In c.Controls 

       If ct.GetType.ToString = "Microsoft.Reporting.WebForms.ExportGroup" Then 

        Dim cbo As DropDownList = CType(ct.controls(0), DropDownList) 

        AddHandler cbo.PreRender, AddressOf cboExportReportViewer_PreRender 

       End If 

      Next 

     End If 

    Next 

End Sub 

Protected Sub cboExportReportViewer_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) 

    Dim cbo = CType(sender, DropDownList) 

    For i As Integer = 0 To cbo.Items.Count - 1 

     If cbo.Items(i).Text.ToLower = "excel" Then 
      cbo.Items.Remove(cbo.Items(i)) 
      Exit Sub 
     End If 

    Next 

End Sub 

... e mettere una chiamata al CustomizeRV(ReportViewer1) in caso page_load

2
public void DisableUnwantedExportFormats() 
{ 
    FieldInfo info; 

    foreach (RenderingExtension extension in reportViewer.ServerReport.ListRenderingExtensions()) 
    { 
     if (extension.Name != "PDF" && extension.Name != "EXCEL") // only PDF and Excel - remove the other options 
     { 
      info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); 
      info.SetValue(extension, false); 
     } 

     if (extension.Name == "EXCEL") // change "Excel" name on the list to "Excel 97-2003 Workbook" 
     { 
      info = extension.GetType().GetField("m_localizedName", BindingFlags.Instance | BindingFlags.NonPublic); 
      if (info != null) info.SetValue(extension, "Excel 97-2003 Workbook"); 
     } 
    } 
} 

Ho provato con l'aggiunta di sopra detto procedimento DisableUnwantedExportFormats() per nascondere opzione Esporta Excel. Quando il report è stato caricato per la prima volta, l'opzione di Excel non diventa visibile.

Tuttavia, quando ho utilizzato lo stesso metodo all'interno dell'evento Drillthrough() "Excel" & l'opzione PDF è visibile nell'elenco a discesa Controlli di esportazione. Ho provato chiamando il metodo nella prima istruzione del mio evento Drillthrough() (come quello che ho usato nel metodo di caricamento della pagina).

Per favore fatemi sapere, Come posso nascondere l'opzione excel nell'evento Drillthrough() di Reportviewer.

0

Se siete interessati a una soluzione rapida javascript utilizzando jQuery ..

sostituire semplicemente il selettore di ReportViewer in basso con il tuo ID discesa.

jQuery ('# ctl00_ContentPlaceHolder1_rptViewer_ctl01_ctl05_ctl00') i bambini() rimuovere()..; jQuery ('# ctl00_ContentPlaceHolder1_rptViewer_ctl01_ctl05_ctl00'). Append ("- Seleziona formato di esportazione -"); jQuery ('# ctl00_ContentPlaceHolder1_rptViewer_ctl01_ctl05_ctl00'). Append ("EXCEL");

Rimuove tutte le opzioni e quindi aggiunge EXCEL come unica opzione.

25

Ho avuto esattamente lo stesso problema e risolto utilizzando il seguente metodo di C#, trovato here:

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

e sulla Page Load:

DisableUnwantedExportFormat(ReportViewer1, "PDF"); 
+0

Ciao ho usato il tuo e funziona solo con PDF e WORD. Come posso provarlo con Excel ?? – user2530748

+1

Ooops l'ho capito. È case sensitive deve essere "Excel". Grazie per il tuo codice ^^ – user2530748

1

Nel codice dietro, caricare un valore nascosto quando mostrando il rapporto

this.ReportServViewer.ServerReport.Refresh(); 
this.hidReportViewing.Value = "algo"; 

quindi utilizzare il seguente javascript per impostare su imer per verificare la visualizzazione dei pulsanti di esportazione. Quando sono renderizzati, rimuovi il pulsante e cancella il timer.

<script> 
var intervalHandler; 
var maxTries = 10; 
var currentTries = 0; 

function removePDFFromReporting() { 
      var clear = false; 
      if (intervalHandler != null) {     
       if ($('#hidReportViewing').val() != '') {      
        var anchor = $("#<%= ReportServViewer.ClientID%>_fixedTable a:contains('PDF')"); 
        if (anchor.length == 0) { 
         currentTries = currentTries + 1; 
         clear = currentTries >= maxTries; 
        } 
        else { 
         anchor.remove(); 
         clear = true;      
        } 
       } 
      } 

      if (clear) { 
       $('#hidReportViewing').val(''); 
       clearInterval(intervalHandler); 
       intervalHandler = null; 
      } 
     } 

</script> 

nel sul carico aggiuntivo (.ready cioè $ (document)())

if ($('#hidReportViewing').val() != '') 
{ 
       intervalHandler = setInterval(removePDFFromReporting, 1500); 
} 
3

Ho avuto lo stesso problema. Potrei ottenere le opzioni di esportazione indesiderate da nascondere quando il report è stato reso, ma non ha funzionato nel caso di un report drill-through.Il seguente codice ha lavorato sia per il genitore e report drill-through, utilizzando un 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); 
      } 
     } 
    } 

Il trucco è quello di chiamare il metodo dal metodo pagina PreRender:

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

soluzione Jquery per reportviewer 2010: mettere questo nel file aspx che contiene il controllo ReportViewer (Assumendo che il ReportViewer si chiama ReportViewer1)

<script type="text/javascript"> 
    $(document).ready(function() { 
     hideExportOptions(); 
    }); 

    function hideExportOptions() { 
     //Find the menu id by getting the parent of the parent of one of the export links 
     var menuID = $("a[onclick=\"$find('ReportViewer1').exportReport('PDF');\"]").parent().parent().attr("id"); 
     if ($("#" + menuID).length > 0) { 
      $("#" + menuID + " div:nth-child(3)").css('display', 'none'); 
     } 
     else { 
      setTimeout("hideExportOptions()", 1000); 
     } 
    } 

</script> 

si attende fino al dr viene eseguito il rendering, quindi nasconde l'opzione scelta. In genere, setTimeout si verifica solo una volta. Puoi nascondere più/altri aggiungendo altri nth-child, il numero è la posizione basata su 1 nel menu a discesa dell'opzione che desideri nascondere.

1

Sono riuscito a farlo dal lato client utilizzando JavaScript nella parte inferiore della pagina.

var exportSelectBox = document.getElementById("ReportViewer1__ctl1__ctl5__ctl0"); 
exportSelectBox.remove(7); 
exportSelectBox.remove(6); 
exportSelectBox.remove(5); 
exportSelectBox.remove(4); 
exportSelectBox.remove(1); 
exportSelectBox.remove(1); 
10

Questo semplice approccio jQuery ha funzionato per me:

$(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(); 
}); 
+0

Ha funzionato come un fascino. Semplice e senza problemi! –

+0

Ha funzionato davvero bene, soluzione semplice e carina. Grazie :) –

+0

Semplice e semplice senza modificare il file di configurazione. –

2
  1. Per Word di riferimento opzione "WORDOPENXML"
  2. Per riferimento opzione Excel a "EXCELOPENXML"
  3. Per riferimento opzione PDF a "PDF"

Regard S.

+0

A questa risposta dovrebbe essere aggiunta una descrizione circostante. Non è molto chiaro. – RacerNerd

1

Per ReportViewer> 2010 Io uso questo aproach realizzato con jQuery

function HideExtension(ext) { 
     var $reportViewer = $("[id*=ReportViewer1]"); 
     var $botons = $reportViewer.find("a"); 
     $botons.each(function (index,element) { 
      if($(element).html()==ext) 
      { 
       $(element).parent().css("display", "none"); 
      } 
     }); 
    } 

basta cambiare il selettore per il proprio e chiamare la funzione da $(document).ready(function(){//here})

Problemi correlati