[]
        
(Showing Draft Content)

IStyleCollection

Interface IStyleCollection

All Superinterfaces:
Iterable<IStyle>

public interface IStyleCollection extends Iterable<IStyle>
Represents a collection of all the IStyle objects in a specified workbook or the active workbook.

This collection stores the workbook's built-in and custom named styles and provides access to them by name or index. Obtain this collection through Workbook.getStyles().


 IStyleCollection styles = workbook.getStyles();
 IStyle normalStyle = styles.get("Normal");
 IStyle customStyle = styles.add("MyStyle");
 worksheet.getRange("A1").setStyle(customStyle);
 
  • Method Details

    • getCount

      int getCount()
      Gets the number of IStyle objects in the collection.

      This count includes the named styles available in the workbook, such as built-in styles and any custom styles added to the collection.

      
       IStyleCollection styles = workbook.getStyles();
       styles.add("DataStyle");
       int count = styles.getCount();
       
      Returns:
      The number of style objects in the collection.
    • get

      IStyle get(String name)
      Returns the IStyle object with the specified name from this collection.

      Use this method to retrieve a workbook style by its name from the current IStyleCollection.

      
       IStyleCollection styles = workbook.getStyles();
       styles.add("DataStyle");
       IStyle style = styles.get("DataStyle");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      name - Specifies the name of an element in the collection.
      Returns:
      The IStyle object with the specified name.
    • get

      IStyle get(int index)
      Returns the IStyle object at the specified index from this collection.

      Use this method to retrieve a built-in or custom named style from the workbook style collection by index.

      
       IStyleCollection styles = workbook.getStyles();
       IStyle style = styles.get(0);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      index - Specifies the index of an element in the collection. Valid values are from 0 to getCount() - 1.
      Returns:
      The IStyle object at the specified index.
      Throws:
      IllegalArgumentException - if index is less than 0 or greater than or equal to getCount().
    • contains

      boolean contains(String name)
      Determines whether the style name is contained in IStyleCollection.

      Use this method to check whether a built-in or custom named style is available in the workbook style collection returned by Workbook.getStyles().

      
       IStyleCollection styles = workbook.getStyles();
       styles.add("DataStyle");
       boolean containsStyle = styles.contains("DataStyle");
       
      Parameters:
      name - The style name to search for.
      Returns:
      true if the collection contains a style with the specified name; otherwise, false.
    • add

      IStyle add(String name)
      Creates a new named IStyle and adds it to the list of styles that are available for the current Workbook.

      This method is functionally equivalent to add(String,IRange) with baseOn = null.

      
       IStyleCollection styles = workbook.getStyles();
       IStyle style = styles.add("DataStyle");
       style.getFont().setBold(true);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      name - The new IStyle name.
      Returns:
      The new IStyle.
    • add

      IStyle add(String name, IRange baseOn)
      Creates a new IStyle and adds it to the list of styles that are available for the current Workbook.

      The new style is based on the style of the specified range. Specify null or use add(String) to base the new style on the Normal style.

      
       IRange cell = worksheet.getRange("A1");
       cell.getFont().setBold(true);
       IStyle style = workbook.getStyles().add("HeaderStyle", cell);
       worksheet.getRange("B1").setStyle(style);
       
      Parameters:
      name - The new IStyle name.
      baseOn - The IRange whose cell style is used as the basis for the new style. Specify null to base the new style on the Normal style.
      Returns:
      The new IStyle.
    • add

      IStyle add(String name, IStyle baseOn)
      Creates a new IStyle and adds it to the list of styles that are available for the current Workbook.

      The new style is created by using an existing IStyle as its basis.

      
       IStyle baseStyle = workbook.getStyles().get("Good");
       IStyle style = workbook.getStyles().add("MyGood", baseStyle);
       style.getFont().setItalic(true);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      name - The new IStyle name.
      baseOn - The IStyle to use as the basis for the new style.
      Returns:
      The new IStyle.