使用 Aspose.Cells 添加 ActiveX 控件
Contents
[
Hide
]
您可以使用 ShapeCollection.addActiveXControl() 方法在 Aspose.Cells 中添加 ActiveX 控件。该方法接受 ControlType 参数,用于指示需要在工作表中添加何种类型的 ActiveX 控件。它有以下值。
一旦将ActiveX控件添加到形状集合中,您可以通过Shape.ActiveXControl属性访问ActiveX控件对象,然后设置其各种属性。
使用Aspose.Cells添加切换按钮ActiveX控件
以下示例代码使用Aspose.Cells添加切换按钮ActiveX控件。请下载使用此代码生成的输出excel文件供您参考。
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddActiveXControl.class); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Add Toggle Button ActiveX Control inside the Shape Collection | |
Shape s = sheet.getShapes().addActiveXControl(ControlType.TOGGLE_BUTTON, 4, 0, 4, 0, 100, 30); | |
// Access the ActiveX control object and set its linked cell property | |
ActiveXControl c = s.getActiveXControl(); | |
c.setLinkedCell("A1"); | |
// Save the worbook in xlsx format | |
wb.save(dataDir + "output.xlsx", SaveFormat.XLSX); |