Aktualisieren Sie die ActiveX ComboBox Steuerelemente
Mögliche Verwendungsszenarien
Sie können die Werte der aktiven ComboBox-Steuerung mit Aspose.Cells lesen oder schreiben. Greifen Sie bitte über die Eigenschaft Shape.ActiveXControl auf die ActiveX-Steuerung zu und überprüfen Sie ihren Typ über die Eigenschaft ActiveXControl.Type, sie sollte den Wert ControlType.ComboBox zurückgeben, und dann casten Sie sie in ein ComboBoxActiveXControl-Objekt und lesen oder ändern Sie seine verschiedenen Eigenschaften.
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.
![]() |
---|
Beispielcode
Der folgende Beispielcode aktualisiert den Wert des ActiveX-ComboBox-Steuerungselements, das sich in der Beispieldatei Excel befindet.
// 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 a workbook | |
Workbook wb = new Workbook(dataDir + "SourceFile.xlsx"); | |
// Access first shape from first worksheet | |
Shape shape = wb.Worksheets[0].Shapes[0]; | |
// Access ActiveX ComboBox Control and update its value | |
if (shape.ActiveXControl != null) | |
{ | |
// Access Shape ActiveX Control | |
ActiveXControl c = shape.ActiveXControl; | |
// Check if ActiveX Control is ComboBox Control | |
if (c.Type == ControlType.ComboBox) | |
{ | |
// Type cast ActiveXControl into ComboBoxActiveXControl and change its value | |
ComboBoxActiveXControl comboBoxActiveX = (ComboBoxActiveXControl)c; | |
comboBoxActiveX.Value = "This is combo box control with updated value."; | |
} | |
} | |
// Save the workbook | |
wb.Save(dataDir + "OutputFile_out.xlsx"); |