Agregar controles ActiveX usando Aspose.Cells
Puede agregar controles ActiveX con Aspose.Cells utilizando el método ShapeCollection.addActiveXControl(). Este método toma un parámetro ControlType que indica qué tipo de control ActiveX debe agregarse dentro de una hoja de cálculo. Tiene los siguientes valores.
- CHECK_BOX
- COMBO_BOX
- COMMAND_BUTTON
- IMAGE
- LABEL
- LIST_BOX
- RADIO_BUTTON
- SCROLL_BAR
- SPIN_BUTTON
- TEXT_BOX
- TOGGLE_BUTTON
- DESCONOCIDO
Una vez que haya agregado el control ActiveX dentro de la colección de formas, puede acceder al objeto de control ActiveX a través de la propiedad Shape.ActiveXControl y luego establecer sus diversas propiedades.
Agregar control ActiveX de botón de alternancia con Aspose.Cells
El siguiente código de muestra agrega un control ActiveX de botón de alternancia utilizando Aspose.Cells. Descargue el archivo de Excel de salida generado con este código para su referencia.
// 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); |