// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("A1").setValue("Original controls"); worksheet.getRange("A:A,C:C").setColumnWidthInPixel(121.0D); IControlCollection controls = worksheet.getControls(); IButton ctl1 = controls.addButton(4.9, 21.6, 127.85, 24.4); ctl1.setText("Sample button"); ctl1.setPrintObject(true); ICheckBox ctl2 = controls.addCheckBox(5.5, 51.5, 121.25, 16.5); ctl2.setText("Sample check box"); IScrollBar ctl3 = controls.addScrollBar(6.8, 79.7, 121.95, 17.30); // Form controls are also shapes. Some features of shapes are available to form controls. // Example 1: Get a button from shapes collection for (IShape shp : worksheet.getShapes()) { if (!shp.getType().equals(ShapeType.FormControl)) { continue; } if (shp.getControl().getFormControlType().equals(FormControlType.Button)) { System.out.println(("Found the sample button. The shape name is " + shp.getName())); break; } } // Example 2: Duplicate the scroll bar shape IShape scrollbarShape = ctl3.getShapeRange().get(0); IShape scrollbar2Shape = scrollbarShape.duplicate(); // Example 3: Copy shapes on cells IRange bottomRightCell = scrollbar2Shape.getBottomRightCell(); IRange copyFrom = worksheet.getRange(0, 0, bottomRightCell.getRow() + 1, bottomRightCell.getColumn() + 1); IRange copyTo = worksheet.getRange(0, bottomRightCell.getColumnCount() + 1, bottomRightCell.getRow(), bottomRightCell.getColumn()); copyFrom.copy(copyTo); copyTo.get(0, 0).setValue("Copied controls"); // Save to an excel file workbook.save("ShapeOfFormControl.xlsx");
// Create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets[0] worksheet.getRange("A1").value = "Original controls" worksheet.getRange("A:A,C:C").columnWidthInPixel = 121.0 val controls = worksheet.controls val ctl1 = controls.addButton(4.9, 21.6, 127.85, 24.4) ctl1.text = "Sample button" ctl1.printObject = true val ctl2 = controls.addCheckBox(5.5, 51.5, 121.25, 16.5) ctl2.text = "Sample check box" val ctl3 = controls.addScrollBar(6.8, 79.7, 121.95, 17.30) // Form controls are also shapes. Some features of shapes are available to form controls. // Example 1: Get a button from shapes collection for (shp in worksheet.shapes) { if (shp.type != ShapeType.FormControl) { continue } if (shp.control.formControlType == FormControlType.Button) { println("Found the sample button. The shape name is " + shp.name) break } } // Example 2: Duplicate the scroll bar shape val scrollbarShape = ctl3.shapeRange[0] val scrollbar2Shape = scrollbarShape.duplicate() // Example 3: Copy shapes on cells val bottomRightCell = scrollbar2Shape.bottomRightCell val copyFrom = worksheet.getRange(0, 0, bottomRightCell.row + 1, bottomRightCell.column + 1) val copyTo = worksheet.getRange(0, bottomRightCell.columnCount + 1, bottomRightCell.row, bottomRightCell.column) copyFrom.copy(copyTo) copyTo[0, 0].value = "Copied controls" // Save to an excel file workbook.save("ShapeOfFormControl.xlsx")