更新ActiveX组合框控件

可能的使用场景

你可以使用 Aspose.Cells for Python via .NET 读取或写入 ActiveX 组合框控件的值。请通过 Shape.active_x_control 属性访问 ActiveX 控件,并通过 ActiveXControl.type 属性检查它的类型,应返回 ControlType.COMBO_BOX 值,并将其强制类型转换为 ComboBoxActiveXControl 对象,然后读取或修改其各种属性。

请下载以下示例代码中使用的 示例 Excel 文件

更新ActiveX ComboBox控件

以下截图显示了样本代码对 样本excel文件 的效果。正如你所看到的,活动X组合框的值已更新为"This is combo box control"。

todo:image_alt_text

示例代码

以下样本代码更新了 样本excel文件 中存在的活动X组合框控件的值。

from aspose import pycore
from aspose.cells import Workbook
from aspose.cells.drawing.activexcontrols import ComboBoxActiveXControl, ControlType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create a workbook
wb = Workbook(dataDir + "SourceFile.xlsx")
# Access first shape from first worksheet
shape = wb.worksheets[0].shapes[0]
# Access ActiveX ComboBox Control and update its value
if shape.active_x_control != None:
# Access Shape ActiveX Control
c = shape.active_x_control
# Check if ActiveX Control is ComboBox Control
if c.type == ControlType.COMBO_BOX:
# Type cast ActiveXControl into ComboBoxActiveXControl and change its value
comboBoxActiveX = pycore.cast(ComboBoxActiveXControl, c)
comboBoxActiveX.value = "This is combo box control with updated value."
# Save the workbook
wb.save(dataDir + "OutputFile_out.xlsx")