// 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");