使用 Aspose.Cells 添加 ActiveX 控件
Contents
[
Hide
]
您可以使用 Aspose.Cells 添加 ActiveX 控件ShapeCollection.AddActiveXControl()方法。这个方法接受一个参数控件类型它告诉需要在工作表中添加什么类型的 ActiveX 控件。它具有以下值。
- 控件类型.CheckBox
- 控件类型.ComboBox
- 控件类型.CommandButton
- 控件类型.Image
- 控件类型.标签
- 控件类型.ListBox
- 控件类型.RadioButton
- 控件类型.滚动条
- 控件类型.SpinButton
- 控件类型.TextBox
- 控件类型.ToggleButton
- 控件类型.Unknown
一旦您在形状集合中添加了 ActiveX 控件,您就可以通过以下方式访问 ActiveX 控件对象形状.ActiveXControl属性,然后设置其各种属性。
以下示例代码使用 Aspose.Cells 添加 Toggle Button ActiveX 控件。
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 workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = wb.Worksheets[0]; | |
// Add Toggle Button ActiveX Control inside the Shape Collection | |
Shape s = sheet.Shapes.AddActiveXControl(ControlType.ToggleButton, 4, 0, 4, 0, 100, 30); | |
// Access the ActiveX control object and set its linked cell property | |
ActiveXControl c = s.ActiveXControl; | |
c.LinkedCell = "A1"; | |
// Save the worbook in xlsx format | |
wb.Save(dataDir + "AddActiveXControls_out.xlsx", SaveFormat.Xlsx); |