Ajouter des contrôles ActiveX à l'aide de Aspose.Cells
Contents
[
Hide
]
Vous pouvez ajouter des contrôles ActiveX avec Aspose.Cells en utilisant leShapeCollection.AddActiveXControl() méthode. Cette méthode prend un paramètreType de contrôlequi indique quel type de contrôle ActiveX doit être ajouté dans une feuille de calcul. Il a les valeurs suivantes.
- ControlType.CheckBoxControlType.CheckBox
- ControlType.ComboBoxControlType.ComboBox
- ControlType.CommandButtonControlType.CommandButtonControlType.CommandButtonControlType.CommandButton
- ControlType.Image
- ControlType.LabelControlType.Label
- ControlType.ListBoxControlType.ListBox
- ControlType.RadioButtonControlType.RadioButtonControlType.RadioButtonControlType.RadioButton
- ControlType.ScrollBarControlType.ScrollBar
- ControlType.SpinButtonControlType.SpinButtonControlType.SpinButtonControlType.SpinButtonControlType.SpinButtonControlType.SpinButtonControlType.SpinButton
- ControlType.TextBox
- ControlType.ToggleButtonControlType.ToggleButtonControlType.ToggleButton
- ControlType.UnknownControlType.Unknown
Une fois que vous avez ajouté le contrôle ActiveX à l’intérieur de la collection de formes, vous pouvez alors accéder à l’objet de contrôle ActiveX viaShape.ActiveXControl propriété, puis définissez ses différentes propriétés.
L’exemple de code suivant ajoute le contrôle ActiveX du bouton bascule à l’aide de Aspose.Cells.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |