更新ActiveX组合框控件
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 读取或写入 ActiveX ComboBox 控件的值。请通过 Shape.ActiveXControl 属性访问 ActiveX 控件,并通过 ActiveXControl.Type 属性检查其类型,它应该返回 ControlType.ComboBox 值,然后将其转换为 ComboBoxActiveXControl 对象并读取或修改其各种属性。
请下载以下示例代码中使用的 示例 Excel 文件。
更新ActiveX ComboBox控件
以下截图显示了样本代码对 样本excel文件 的效果。正如你所看到的,活动X组合框的值已更新为"This is combo box control"。
![]() |
---|
示例代码
以下样本代码更新了 样本excel文件 中存在的活动X组合框控件的值。
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-.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"); |