Using ActiveX Controls in Excel with C#

This article guides on using ActiveX controls in Excel with C#. It has the details to set the IDE for development, a list of steps defining the process, and a sample code for adding Excel Active X control using C#. You will learn to add ActiveX control and then access it to update or read the control value.

Steps to Add ActiveX Controls in Excel using C#

  1. Set the IDE to use Aspose.Cells for .NET for working with ActiveX controls
  2. Create an Excel file using the Workbook class for adding ActiveX control
  3. Access the shapes collection from a sheet and call the AddActiveXControl() method to add controls
  4. Access the ActiveX control and send its linked cell
  5. For setting a specific property of a control, typecast the ActiveX control and set the value
  6. For updating or accessing a control, check its control type and update the desired value

These steps summarize how to use ActiveX controls in Excel using C#. Commence the process by accessing the shapes collection from a sheet in a Workbook and calling the AddActiveXControl() method in the ShapeCollection class. Provide the control type, target cell, and size of the ActiveX control, and link the control with a cell for manipulating its value.

Code to Add ActiveX Command Button using C#

This code demonstrates adding a Combo Box ActiveX control using C# in Excel sheet. The AddActiveXControl() method returns a reference to the newly added shape that you can use to set the linked cell and other properties such as font, color, shadow, and text alignment, to list a few. Similarly, if you typecast the shape to a specific control, you will get a vast range of properties for customizing the control.

This article has taught us how to add and access ActiveX controls in an Excel file. For adding an image in an Excel file, refer to the article on how to add image in Excel cell using C#.

 English