Agregar controles ActiveX usando Aspose.Cells
Puedes agregar controles ActiveX con Aspose.Cells usando el método ShapeCollection.AddActiveXControl(). Este método toma un parámetro ControlType que indica qué tipo de control ActiveX se debe agregar dentro de una hoja de cálculo. Tiene los siguientes valores.
- ControlType.CheckBox
- ControlType.ComboBox
- ControlType.CommandButton
- ControlType.Image
- ControlType.Label
- ControlType.ListBox
- ControlType.RadioButton
- ControlType.ScrollBar
- ControlType.SpinButton
- ControlType.TextBox
- ControlType.ToggleButton
- ControlType.Unknown
Una vez que hayas agregado el control ActiveX dentro de la colección de formas, puedes acceder al objeto control ActiveX a través de la propiedad Shape.ActiveXControl y luego configurar sus diferentes propiedades.
El siguiente código de ejemplo agrega el control de botón de alternancia ActiveX utilizando Aspose.Cells.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = wb.Worksheets[0]; | |
// Add Toggle Button ActiveX Control inside the Shape Collection | |
Shape s = sheet.Shapes.AddActiveXControl(ControlType.ToggleButton, 4, 0, 4, 0, 100, 30); | |
// Access the ActiveX control object and set its linked cell property | |
ActiveXControl c = s.ActiveXControl; | |
c.LinkedCell = "A1"; | |
// Save the worbook in xlsx format | |
wb.Save(dataDir + "AddActiveXControls_out.xlsx", SaveFormat.Xlsx); |