[]
        
(Showing Draft Content)

IControlCollection

Interface IControlCollection

All Superinterfaces:
Iterable<IControl>

public interface IControlCollection extends Iterable<IControl>
Represents the collection of form controls in a worksheet.

Use this interface to access, add, and enumerate worksheet form controls such as buttons, check boxes, labels, drop-down lists, and other supported control types. Controls can be retrieved by zero-based index or by name, and the collection can be iterated because it extends Iterable of IControl.


 IControlCollection controls = worksheet.getControls();
 IButton button = controls.addButton(20, 20, 100, 24);
 button.setName("submitButton");
 IControl control = controls.get("submitButton");
 
  • Method Details

    • getCount

      int getCount()
      Gets the count of controls.

      Returns the number of form controls currently contained in this collection.

      
       IButton button = worksheet.getControls().addButton(20, 20, 100, 24);
       IDropDown dropDown = worksheet.getControls().addDropDown(20, 60, 120, 24);
       int count = worksheet.getControls().getCount();
       
      Returns:
      The number of controls in this collection.
    • get

      IControl get(int index)
      Gets control by index.

      Use this method to retrieve a control from the collection by its zero-based position.

      
       IButton button = worksheet.getControls().addButton(20, 20, 100, 24);
       button.setText("Submit");
       IControl control = worksheet.getControls().get(0);
       control.setLeft(40);
       
      Parameters:
      index - The zero-based index of the control to retrieve.
      Returns:
      The control at the specified index.
      Throws:
      IndexOutOfBoundsException - if index is less than 0 or greater than or equal to the number of controls in the collection.
    • get

      IControl get(String name)
      Gets control by name.

      Returns the control whose name matches the specified name. Use IControl.setName(String) to assign a custom name before retrieving a control from the collection.

      
       IButton button = worksheet.getControls().addButton(20, 20, 100, 24);
       button.setName("submitButton");
       IControl control = worksheet.getControls().get("submitButton");
       
      Parameters:
      name - The name of the control to retrieve.
      Returns:
      The control with the specified name, or null if no control with that name exists.
    • addButton

      IButton addButton(double left, double top, double width, double height)
      Adds a new IButton.

      Creates a button control at the specified position and size in the worksheet's control collection.

      
       IButton button = worksheet.getControls().addButton(20, 20, 100, 24);
       button.setText("Submit");
       
      Parameters:
      left - The left margin of the button.
      top - The top margin of the button.
      width - The width of the button.
      height - The height of the button.
      Returns:
      The newly added IButton.
    • addDropDown

      IDropDown addDropDown(double left, double top, double width, double height)
      Adds a new IDropDown.

      Creates a drop-down form control at the specified position with the specified size on the worksheet. Use the returned control to add items, bind a linked cell, or set the selected item.

      
       IDropDown dropDown = worksheet.getControls().addDropDown(20, 20, 120, 24);
       dropDown.getItems().add(new DropDownItem("North"));
       dropDown.getItems().add(new DropDownItem("South"));
       dropDown.setSelectedIndex(0);
       
      Parameters:
      left - The left position of the control.
      top - The top position of the control.
      width - The width of the control.
      height - The height of the control.
      Returns:
      The newly created IDropDown.
    • addCheckBox

      ICheckBox addCheckBox(double left, double top, double width, double height)
      Adds a new ICheckBox.

      Creates a check box form control in the worksheet at the specified position and size, and returns the created control for further configuration.

      
       ICheckBox checkBox = worksheet.getControls().addCheckBox(54, 13.2, 64.2, 18);
       checkBox.setText("Accept terms");
       checkBox.setLinkedCell(worksheet.getRange("A1"));
       
      Parameters:
      left - The horizontal position of the check box.
      top - The vertical position of the check box.
      width - The width of the check box.
      height - The height of the check box.
      Returns:
      The created ICheckBox.
    • addSpinner

      ISpinner addSpinner(double left, double top, double width, double height)
      Adds a new ISpinner.

      Use this method to place a spinner form control on the worksheet and then configure its linked cell and range settings through the returned ISpinner.

      
       ISpinner spinner = worksheet.getControls().addSpinner(20, 20, 18, 72);
       spinner.setLinkedCell(worksheet.getRange("A1"));
       spinner.setMin(0);
       spinner.setMax(10);
       spinner.setSmallChange(1);
       
      Parameters:
      left - The horizontal position of the spinner.
      top - The vertical position of the spinner.
      width - The width of the spinner.
      height - The height of the spinner.
      Returns:
      The newly created ISpinner.
    • addListBox

      IListBox addListBox(double left, double top, double width, double height)
      Adds a new IListBox.

      Use the returned list box to add selectable items or link the control to a worksheet cell.

      
       IListBox listBox = worksheet.getControls().addListBox(24.1, 273.1, 170, 78.69);
       listBox.getItems().add(new ListBoxItem("North"));
       listBox.getItems().add(new ListBoxItem("South"));
       listBox.setSelectedIndex(0);
       
      Parameters:
      left - The left position of the list box.
      top - The top position of the list box.
      width - The width of the list box.
      height - The height of the list box.
      Returns:
      The added IListBox.
    • addOptionButton

      IOptionButton addOptionButton(double left, double top, double width, double height)
      Adds a new IOptionButton.

      Creates an option button control at the specified location and size and returns the created control. Option buttons placed inside the bounds of the same IGroupBox participate in the same selection group; otherwise, they belong to the worksheet's default group.

      
       IOptionButton optionButton = worksheet.getControls().addOptionButton(39.45, 67.1, 98, 15.6);
       optionButton.setText("North");
       optionButton.setLinkedCell(worksheet.getRange("A1"));
       
      Parameters:
      left - The left position of the option button.
      top - The top position of the option button.
      width - The width of the option button.
      height - The height of the option button.
      Returns:
      The newly added IOptionButton.
    • addGroupBox

      IGroupBox addGroupBox(double left, double top, double width, double height)
      Adds a new IGroupBox.

      Creates a group box control at the specified location and size on the worksheet. A group box can be used to organize related controls, such as IOptionButton controls.

      
       IGroupBox groupBox = worksheet.getControls().addGroupBox(29.75, 48.2, 136.5, 113.99);
       groupBox.setText("Group 1");
       
      Parameters:
      left - The left coordinate of the group box.
      top - The top coordinate of the group box.
      width - The width of the group box.
      height - The height of the group box.
      Returns:
      The created IGroupBox.
    • addLabel

      ILabel addLabel(double left, double top, double width, double height)
      Adds a new ILabel.

      Use this method to place a label control on the worksheet by specifying its position and size.

      
       ILabel label = worksheet.getControls().addLabel(20, 20, 100, 24);
       label.setText("Resolution");
       
      Parameters:
      left - The distance between the left edge of the worksheet and the label.
      top - The distance between the top edge of the worksheet and the label.
      width - The width of the label.
      height - The height of the label.
      Returns:
      The newly added label control.
    • addScrollBar

      IScrollBar addScrollBar(double left, double top, double width, double height)
      Adds a new IScrollBar.

      Creates a scroll bar control on the worksheet at the specified position and size, and returns the newly added control.

      
       IScrollBar scrollBar = worksheet.getControls().addScrollBar(20, 20, 120, 18);
       scrollBar.setMin(0);
       scrollBar.setMax(10);
       scrollBar.setLinkedCell(worksheet.getRange("A1"));
       
      Parameters:
      left - The distance from the left edge of the worksheet to the control.
      top - The distance from the top edge of the worksheet to the control.
      width - The width of the control.
      height - The height of the control.
      Returns:
      The newly added IScrollBar.
    • indexOf

      int indexOf(IControl control)
      Gets the index of a control.

      Returns the zero-based position of the specified control in this collection.

      
       IControlCollection controls = worksheet.getControls();
       IButton button = controls.addButton(20, 20, 100, 24);
       int index = controls.indexOf(button);
       
      Parameters:
      control - The control to find. If null, this method returns -1.
      Returns:
      If found, returns the index of the control. Otherwise, returns -1.
    • clear

      void clear()
      Removes all controls from a IControlCollection.

      After this method is called, the collection is empty.

      
       IControlCollection controls = worksheet.getControls();
       controls.addButton(20, 20, 100, 24);
       controls.addCheckBox(54, 13.2, 64.2, 18);
       controls.clear();