Ribbon Functions

These functions can be used to manipulate the Excel ribbon.

The ribbon can be updated at any time, for example as PyXLL is loading via the xl_on_open and xl_on_reload event handlers, or from a menu using using xl_menu.

See the section on customizing the ribbon for more details.

get_ribbon_xml

get_ribbon_xml()

Returns the XML used to customize the Excel ribbon bar, as a string.

See the section on customizing the ribbon for more details.

set_ribbon_xml

set_ribbon_xml(xml, reload=True)

Sets the XML used to customize the Excel ribbon bar.

Parameters:
  • xml – XML to set, as a string.
  • reload – If True, the ribbon bar will be reloaded using the new XML (does not reload PyXLL).

See the section on customizing the ribbon for more details.

set_ribbon_tab

set_ribbon_tab(xml, tab_id=None, reload=True)

Sets a single tab in the ribbon using an XML fragment.

Instead of replacing the whole ribbon XML this function takes a tab element from the input XML and updates the ribbon XML with that tab.

If multiple tabs exist in the input XML, the first who’s id attribute matches tab_id is used (or simply the first tab element if tab_id is None).

If a tab already exists in the ribbon XML with the same id attribute then it is replaced, otherwise the new tab is appended to the tabs element.

Parameters:
  • xml – XML document containing at least on tab element.
  • tab_idid of the tab element to set (or None to use the first tab element in the document).
  • reload – If True, the ribbon bar will be reloaded using the new XML (does not reload PyXLL).

remove_ribbon_tab

remove_ribbon_tab(tab_id, reload=True)

Removes a single tab from the ribbon XML where the tab element’s id attribute matches tab_id.

Parameters:
  • tab_id – id of the tab element to remove.
  • reload – If True, the ribbon bar will be reloaded using the new XML (does not reload PyXLL).
Returns:

True if a tab was removed, False otherwise.