Ajouter des contrôles ActiveX
Vous pouvez ajouter des contrôles ActiveX avec Aspose.Cells pour Python via .NET en utilisant la méthode ShapeCollection.add_active_x_control(). Cette méthode prend un paramètre ControlType qui indique le type de contrôle ActiveX à ajouter dans une feuille de calcul. Elle possède les valeurs suivantes.
- ControlType.COMMAND_BUTTON
- ControlType.COMBO_BOX
- ControlType.CHECK_BOX
- ControlType.LIST_BOX
- ControlType.TEXT_BOX
- ControlType.SPIN_BUTTON
- ControlType.RADIO_BUTTON
- ControlType.LABEL
- ControlType.IMAGE
- ControlType.TOGGLE_BUTTON
- ControlType.SCROLL_BAR
- ControlType.BAR_CODE
- ControlType.INCONNU
Une fois que vous avez ajouté le contrôle ActiveX à l’intérieur de la collection de formes, vous pouvez ensuite accéder à l’objet contrôle ActiveX via la propriété Shape.active_x_control et définir ensuite ses différentes propriétés.
Le code d’exemple suivant ajoute un contrôle ActiveX de bouton de basculement en utilisant Aspose.Cells pour Python via .NET.
from aspose.cells import SaveFormat, Workbook | |
from aspose.cells.drawing.activexcontrols import ControlType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object | |
wb = Workbook() | |
# Access first worksheet | |
sheet = wb.worksheets[0] | |
# Add Toggle Button ActiveX Control inside the Shape Collection | |
s = sheet.shapes.add_active_x_control(ControlType.TOGGLE_BUTTON, 4, 0, 4, 0, 100, 30) | |
# Access the ActiveX control object and set its linked cell property | |
c = s.active_x_control | |
c.linked_cell = "A1" | |
# Save the worbook in xlsx format | |
wb.save(dataDir + "AddActiveXControls_out.xlsx", SaveFormat.XLSX) |