Disabling right click option on the Report Viewer

Hi Team,

I want to know how to disable export to Excel(or csv or pdf) option on the Report Viewer when we right click on it?

Is there a option in the versions from 7.9.6?

1 Like

To remove the entire popup menu:

from org.apache.commons.lang3.reflect import FieldUtils
reportViewer = event.source.parent.getComponent('Report Viewer')
FieldUtils.writeField(reportViewer, "popupMenu", None, True)

If you want more granular control, you’ll have to dive into the popupMenu field and modify the JMenu there.


Hi paul,

Thanks for your immediate response, But can you please tell me Where can i find/Run the scripts to make the adjustments.
Actually i want to disable only save as XLS Option from Report viewer.


Hi Paul,

Can you send me the updated script below which only removes the Save as XLS option from the PopupMenu?

FieldUtils.writeField (reportViewer, “popupMenu”, None, True)

I don’t have the code written, but here’s what you would need to do:

  1. Use FieldUtils.readField to get the current value of the popupMenu field, which will be a JPopupMenu.
  2. Go through each sub element on the menu with getSubElements()
  3. Find the menu item that represents the ‘Save as XLS’ option - you will probably need to getComponent() on each menu item, then check its defined text (getText())

Thank you i will try this :slight_smile:

I have a project where the “Export to Excel” option from the reporting pop-up menu is locking the customers computers. They have requested that the entire pop-up menu be disabled. I tried adding the code you suggested above to the onReportGenerated portion of the report viewer component, but it did not disable the menu.
Could you elaborate on where the code should be placed and if I need to install anything on the gateway computer to get this to work.

Put it on windowOpened or internalFrameActivated and change the component reference accordingly. You need it to run at least once as soon as the window starts up, so that the component has no popup menu - the onReportGenerated function is probably firing too “late” in the process.

Thank you. internalFrameActivated did the trick.

I needed this functionality, so I wrote a little segment of code that will allow you to easily remove any of the right-click print options you don’t want. You just need your reference to the Report Viewer and a collection of actionOptions that you want on the right-click menu (spelling and capitalization must be exact!) Based on PGriffith’s recommendation above.

from org.apache.commons.lang3.reflect import FieldUtils

actionOptions = ["Print", "Save as PDF", "Save as XLS", "Save as HTML", "Save as PNG"]

if len(actionOptions) <> 0:	
	popupMenu = FieldUtils.readField(reportViewer, "popupMenu", True)
	menuItems = popupMenu.getSubElements()
	for count in range(len(menuItems)-1, -1, -1):
		if menuItems[count].text not in actionOptions:

Thanks for sharing this with us.

I am trying to have this working but keep getting the error:

note: I added the following line to reference the report viewer:
reportViewer = system.gui.getParentWindow(event).getComponentForPath(‘Root Container.My_Report’).name

any advise?

Thanks in advance

Drop the .name; you’re referencing the component correctly, but then getting its name, instead of the component itself.

Thanks for the swift response, it is working now.