PyXLL The Python Excel Add-In
  • Product
    • Features
    • Get Started
    • Request Demo
    • Download
  • Pricing
  • Resources
    • Documentation
    • Blog
    • Videos
    • FAQ
    • Learn Python
    • Customer Portal
    • About Us
  • Support
    • Documentation
    • Videos
    • FAQ
    • Contact Us
  • Contact Us
Table of Contents
  • PyXLL Documentation
  • Introduction to PyXLL
  • User Guide
    • Installing PyXLL
    • Configuring PyXLL
    • Worksheet Functions
    • Macro Functions
    • Real Time Data
    • Cell Formatting
    • Charts and Plotting
    • Custom Task Panes
    • ActiveX Controls
      • PySide and PyQt
      • wxPython
      • Tkinter
      • Other UI Toolkits
      • Resizing ActiveX Controls
      • Other Considerations
    • Using Pandas in Excel
    • Customizing the Ribbon
    • Context Menu Functions
    • Working with Tables
    • Python as a VBA Replacement
    • Menu Functions
    • Reloading and Rebinding
    • Error Handling
    • Deploying your add-in
    • Workbook Metadata
  • Video Guides and Tutorials
  • API Reference
  • What’s new in PyXLL 5
  • Changelog
Close

ActiveX Controls¶

Similar to Custom Task Panes, Python UI controls can also be embedded as a control as part of the Excel worksheet.

These can be used for custom user interfaces that form part of the worksheet. For example, controls for a dashboard or for running more complex tasks that don’t naturally fit into Excel’s grid.

Note

For user interface controls that are hosted in a panel that can be floating or docked alongside the Excel worksheet see Custom Task Panes.

PyXLL has support for the following Python UI tookits.

  • PySide and PyQt
  • wxPython
  • Tkinter
  • Other UI Toolkits
A Python user interface in Excel

A Python user interface in Excel¶

ActiveX controls can be created using a control or widget from any of the supported Python UI toolkits by calling the PyXLL function create_activex_control. ActiveX controls are objects embedded in the Excel worksheet. The initial position and size can be set when calling create_activex_control.

For specific details of creating an ActiveX control with any of the supported Python UI toolkits see the links above.

Resizing ActiveX Controls¶

To move or resize the ActiveX control you first need to enable Design Mode.

To enable Design Mode, go to the Developer tab in the Excel ribbon and select Design Mode.

Whilst in Design Mode a bitmap preview will be displayed instead of the web control. You can now move and resize this shape. There may be some lag between resizing the preview image and the preview image updating.

To return to the interactive web widget, unselect Design Mode.

Entering design mode

See the API reference for create_activex_control for more details.

Other Considerations¶

  1. The Python control hosted in an ActiveX control is not saved with the workbook.

    When opening a workbook that was saved with ActiveX controls added, by default you will see a placeholder instead of Python control.

    To recreate the Python control when the workbook is opened, one solution is to use a worksheet function that recalculates when the workbook is opened. By passing name to create_activex_control you can update an existing control with the newly created Python control.

    See Creating an ActiveX Control from a Worksheet Function for more details about how to do this.

  2. ActiveX controls don’t zoom in or out when zooming in or out of the Excel worksheet.

    The size of the control will change as you zoom, but the size of the contents will not automatically be scaled.

    You will need to bear this in mind when designing your user interface to ensure that it handles being resized correctly, if you want the Excel user to be able to change the zoom in Excel and still be able to use the control.

« Other UI Toolkits
PySide and PyQt »
  • Home
  • Product
  • Features
  • Documentation
  • Download
  • Pricing
  • Support
  • Documentation
  • Videos
  • FAQ
  • Learn Python
  • Contact Us
  • About
  • About Us
  • Legal
  • Blog
© Copyright PyXLL Ltd