Uppdatera ActiveX ComboBox Control
Contents
[
Hide
]
Möjliga användningsscenarier
Du kan läsa eller skriva värdena för ActiveX ComboBox Control med Aspose.Cells. Vänligen få tillgång till ActiveX-kontrollen viaShape.ActiveXControl egendom och kontrollera dess typ viaActiveXControl.Type egendom, bör den återvändaControlType.ComboBox värde och sedan typcasta det iComboBoxActiveXControlobjekt och läsa eller ändra dess olika egenskaper.
Vänligen ladda nerexempel på excel-fil används i följande exempelkod ochoutput excel-fil genereras av det.
Uppdatera ActiveX ComboBox Control
Följande skärmdump visar effekten av exempelkoden påexempel på excel-filSom du kan se har ActiveX ComboBox-värdet uppdaterats till “Detta är combobox-kontroll”.
Exempelkod
Följande exempelkod uppdaterar värdet för ActiveX ComboBox Control som finns inutiexempel på excel-fil.
This file contains 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UpdateActiveXComboBoxControl.class) + "articles/"; | |
// Create a workbook | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first shape from first worksheet | |
Shape shape = wb.getWorksheets().get(0).getShapes().get(0); | |
// Access ActiveX ComboBox Control and update its value | |
if (shape.getActiveXControl() != null) { | |
// Access Shape ActiveX Control | |
ActiveXControl c = shape.getActiveXControl(); | |
// Check if ActiveX Control is ComboBox Control | |
if (c.getType() == ControlType.COMBO_BOX) { | |
// Type cast ActiveXControl into ComboBoxActiveXControl and | |
// change its value | |
ComboBoxActiveXControl comboBoxActiveX = (ComboBoxActiveXControl) c; | |
comboBoxActiveX.setValue("This is combo box control."); | |
} | |
} | |
// Save the workbook | |
wb.save(dataDir + "UpdateActiveXComboBoxControl_out.xlsx"); |