更新 ActiveX ComboBox 控件
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 读取或写入 ActiveX ComboBox 控件的值。请通过以下方式访问 ActiveX 控件形状.ActiveXControl属性并通过检查其类型ActiveXControl.类型财产,它应该返回控件类型.ComboBox值,然后将其类型转换为组合框ActiveXControl对象并读取或修改其各种属性。
请下载示例 excel 文件在下面的示例代码中使用。
更新 ActiveX ComboBox 控件
下面的截图展示了示例代码对示例 excel 文件.如您所见,ActiveX ComboBox 值已更新为“This is combo box control”。
![]() |
---|
示例代码
以下示例代码更新了存在于示例 excel 文件.
This file contains hidden or 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-.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"); |