使用 Aspose.Cells 添加 ActiveX 控件
Contents
[
Hide
]
可以使用 ShapeCollection.addActiveXControl() 方法向工作表添加 ActiveX 控件。该方法的参数 ControlType 指示需要添加的 ActiveX 控件类型。其取值如下:
一旦将ActiveX控件添加到形状集合中,您可以通过Shape.ActiveXControl属性访问ActiveX控件对象,然后设置其各种属性。
使用Aspose.Cells添加切换按钮ActiveX控件
以下示例代码使用Aspose.Cells添加切换按钮ActiveX控件。请下载使用此代码生成的输出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-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); |