Aktualisieren Sie die ActiveX ComboBox Steuerelemente

Mögliche Verwendungsszenarien

Sie können die Werte eines ActiveX-ComboBox-Steuerelements mit Aspose.Cells für Python via .NET lesen oder schreiben. Greifen Sie auf das ActiveX-Steuerelement über die Shape.active_x_control-Eigenschaft zu und überprüfen Sie den Typ über die ActiveXControl.type-Eigenschaft. Diese sollte den Wert ControlType.COMBO_BOX zurückgeben. Casten Sie es dann in ein ComboBoxActiveXControl-Objekt, um die verschiedenen Eigenschaften zu lesen oder zu ändern.

Bitte laden Sie die im folgenden Beispielcode verwendete Beispieldatei herunter.

Aktualisieren Sie das ActiveX-ComboBox-Steuerelement

Der folgende Screenshot zeigt die Auswirkung des Beispielcodes auf die Beispieldatei. Wie Sie sehen können, wurde der Wert der ActiveX-ComboBox auf “Dies ist die Kombinationsfeldsteuerung” aktualisiert.

todo:image_alt_text

Beispielcode

Der folgende Beispielcode aktualisiert den Wert des ActiveX-ComboBox-Steuerungselements, das sich in der Beispieldatei Excel befindet.

from aspose import pycore
from aspose.cells import Workbook
from aspose.cells.drawing.activexcontrols import ComboBoxActiveXControl, 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 a workbook
wb = Workbook(dataDir + "SourceFile.xlsx")
# Access first shape from first worksheet
shape = wb.worksheets[0].shapes[0]
# Access ActiveX ComboBox Control and update its value
if shape.active_x_control != None:
# Access Shape ActiveX Control
c = shape.active_x_control
# Check if ActiveX Control is ComboBox Control
if c.type == ControlType.COMBO_BOX:
# Type cast ActiveXControl into ComboBoxActiveXControl and change its value
comboBoxActiveX = pycore.cast(ComboBoxActiveXControl, c)
comboBoxActiveX.value = "This is combo box control with updated value."
# Save the workbook
wb.save(dataDir + "OutputFile_out.xlsx")