Update ActiveX ComboBox Control

Possible Usage Scenarios

You can read or write the values of ActiveX ComboBox Control using Aspose.Cells. Please access the ActiveX Control via Shape.ActiveXControl property and check its type via ActiveXControl.Type property, it should return ControlType.ComboBox value and then typecast it into ComboBoxActiveXControl object and read or modify its various properties.

Please download the sample excel file used in the following sample code and the output excel file generated by it.

Update ActiveX ComboBox Control

The following screenshot shows the effect of the sample code on the sample excel file. As you can see, the ActiveX ComboBox value has been updated to “This is combo box control”.

todo:image_alt_text

Sample Code

The following sample code updates the value of ActiveX ComboBox Control present inside the sample excel file.

// 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");