[]
        
(Showing Draft Content)

IStyle

Interface IStyle


public interface IStyle
Represents a style that can be applied to a range.

An IStyle defines formatting such as font, borders, fill, number format, alignment, and protection settings for cells. Styles are typically created or retrieved through the workbook's IStyleCollection and then applied to an IRange.


 IStyle style = workbook.getStyles().add("Highlight");
 style.getFont().setBold(true);
 style.setHorizontalAlignment(HorizontalAlignment.Center);
 worksheet.getRange("A1").setStyle(style);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Deletes this style.
    void
    Generates the named style from the JSON string.
    boolean
    Gets whether text is automatically indented when the text alignment in a cell is set to equal distribution either horizontally or vertically.
    Returns the IBorders collection that represents the borders of a style.
    boolean
    Gets whether the style is a built-in style.
    Returns the IFont object that represents this style's font.
    boolean
    Gets whether formulas are hidden when the worksheet is protected.
    Gets the horizontal alignment for this style.
    boolean
    Gets whether style includes the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties.
    boolean
    Gets whether the style includes the Color, ColorIndex, LineStyle, and Weight border properties.
    boolean
    Gets whether the style includes the Bold, Color, ColorIndex, FontStyle, Italic, Name, OutlineFont, Shadow, Size, Strikethrough, Subscript, Superscript, and Underline font properties.
    boolean
    Gets whether the style includes the NumberFormat property.
    boolean
    Gets whether the style includes the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.
    boolean
    Gets whether the style includes the FormulaHidden and Locked properties.
    int
    Gets the indent level for the style.
    Returns an IInterior object that represents this style's fill formatting.
    boolean
    Gets whether the object is locked; false if the object can be modified when the sheet is protected.
    Returns the name of the object.
    Gets the format code for the object as a string in the language of the user.
    int
    Gets the text orientation.
    boolean
    Gets whether the text automatically shrinks to fit in the available column width.
    Gets the vertical alignment of the specified object.
    boolean
    Gets whether text wraps automatically.
    void
    setAddIndent(boolean value)
    Sets whether text is automatically indented when the text alignment in a cell is set to equal distribution either horizontally or vertically.
    void
    setFormulaHidden(boolean value)
    Sets whether formulas are hidden when the worksheet is protected.
    void
    Sets the horizontal alignment for the specified object.
    void
    setIncludeAlignment(boolean value)
    Sets whether the style includes the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties.
    void
    setIncludeBorder(boolean value)
    Sets whether the style includes the Color, ColorIndex, LineStyle, and Weight border properties.
    void
    setIncludeFont(boolean value)
    Sets whether the style includes the Bold, Color, ColorIndex, FontStyle, Italic, Name, OutlineFont, Shadow, Size, Strikethrough, Subscript, Superscript, and Underline font properties.
    void
    setIncludeNumber(boolean value)
    Sets whether the style includes the NumberFormat property.
    void
    setIncludePatterns(boolean value)
    Sets whether the style includes the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.
    void
    setIncludeProtection(boolean value)
    Sets whether the style includes the FormulaHidden and Locked properties.
    void
    setIndentLevel(int value)
    Sets the indent level for the style.
    void
    setLocked(boolean value)
    Sets whether the object is locked; false if the object can be modified when the sheet is protected.
    void
    Sets the format code for the object as a string in the language of the user.
    void
    setOrientation(int value)
    Sets the text orientation.
    void
    setShrinkToFit(boolean value)
    Sets whether the text automatically shrinks to fit in the available column width.
    void
    Sets the vertical alignment for this style.
    void
    setWrapText(boolean value)
    Sets whether text wraps automatically.
    Generates a JSON string from the named style.
  • Method Details

    • getAddIndent

      boolean getAddIndent()
      Gets whether text is automatically indented when the text alignment in a cell is set to equal distribution either horizontally or vertically.

      Use this method to determine whether the style keeps the automatic indent setting for distributed text alignment.

      
       IStyle style = workbook.getStyles().add("distributedIndent");
       style.setHorizontalAlignment(HorizontalAlignment.Distributed);
       style.setAddIndent(true);
       worksheet.getRange("A1").setStyle(style);
       boolean addIndent = style.getAddIndent();
       
      Returns:
      true if text is automatically indented for distributed alignment; otherwise, false.
    • setAddIndent

      void setAddIndent(boolean value)
      Sets whether text is automatically indented when the text alignment in a cell is set to equal distribution either horizontally or vertically.

      This setting is relevant when the style uses distributed alignment, such as setHorizontalAlignment(HorizontalAlignment) or setVerticalAlignment(VerticalAlignment). Set this parameter to true to enable automatic indentation for distributed text, or false to disable it.

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Distributed text");
       IStyle style = workbook.getStyles().add("distributedIndent");
       style.setHorizontalAlignment(HorizontalAlignment.Distributed);
       style.setAddIndent(true);
       cell.setStyle(style);
       
      Parameters:
      value - true to automatically indent text when distributed alignment is used; otherwise, false.
    • getBorders

      IBorders getBorders()
      Returns the IBorders collection that represents the borders of a style.

      Use this method to access and modify the border settings stored in the style.

      
       IStyle style = workbook.getStyles().add("borderStyle");
       style.getBorders().setLineStyle(BorderLineStyle.DashDot);
       worksheet.getRange("A1").setStyle(style);
       IBorders borders = style.getBorders();
       
      Returns:
      The border collection for the style.
    • getBuiltIn

      boolean getBuiltIn()
      Gets whether the style is a built-in style.

      Use this method to determine whether a style comes from the built-in workbook styles rather than a custom named style.

      
       IStyle normalStyle = workbook.getStyles().get("Normal");
       worksheet.getRange("A1").setStyle(normalStyle);
       boolean builtIn = normalStyle.getBuiltIn();
       
      Returns:
      true if the style is built in; otherwise, false.
    • getFont

      IFont getFont()
      Returns the IFont object that represents this style's font.

      Use this method to access font settings such as bold, size, color, and font name for the style.

      
       IStyle style = workbook.getStyles().add("headerStyle");
       style.getFont().setBold(true);
       worksheet.getRange("A1").setStyle(style);
       IFont font = style.getFont();
       
      Returns:
      The font object for the style.
    • getFormulaHidden

      boolean getFormulaHidden()
      Gets whether formulas are hidden when the worksheet is protected.

      Use this method to determine whether cells that use this style hide their formulas after worksheet protection is enabled.

      
       IStyle style = workbook.getStyles().add("hiddenFormulaStyle");
       style.setFormulaHidden(true);
       worksheet.getRange("A1").setStyle(style);
       boolean hidden = style.getFormulaHidden();
       
      Returns:
      true if formulas are hidden for this style when the worksheet is protected; otherwise, false.
    • setFormulaHidden

      void setFormulaHidden(boolean value)
      Sets whether formulas are hidden when the worksheet is protected.

      Use this method to control the formula visibility setting stored in the style. When this style is applied to a cell or range, the formula is hidden if worksheet protection is enabled.

      
       IRange cell = worksheet.getRange("A1");
       cell.setFormula("=B1+C1");
       IStyle style = workbook.getStyles().add("hiddenFormulaStyle");
       style.setFormulaHidden(true);
       cell.setStyle(style);
       
      Parameters:
      value - true to hide formulas for cells that use this style when the worksheet is protected; otherwise, false.
    • getHorizontalAlignment

      HorizontalAlignment getHorizontalAlignment()
      Gets the horizontal alignment for this style.

      Use this method to retrieve the horizontal alignment stored in the style.

      
       IStyle style = workbook.getStyles().add("centerStyle");
       style.setHorizontalAlignment(HorizontalAlignment.Center);
       worksheet.getRange("A1").setStyle(style);
       HorizontalAlignment alignment = style.getHorizontalAlignment();
       
      Returns:
      The horizontal alignment defined for the style.
    • setHorizontalAlignment

      void setHorizontalAlignment(HorizontalAlignment value)
      Sets the horizontal alignment for the specified object.

      Use this method to define how content is aligned horizontally when the style is applied to a cell or range.

      
       IStyle style = workbook.getStyles().add("centerStyle");
       style.setHorizontalAlignment(HorizontalAlignment.Center);
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - The horizontal alignment to apply to the style.
    • getIncludeAlignment

      boolean getIncludeAlignment()
      Gets whether style includes the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties.

      Use this method to determine whether alignment-related settings participate when the style is applied.

      
       IStyle style = workbook.getStyles().add("alignmentStyle");
       style.setHorizontalAlignment(HorizontalAlignment.Right);
       style.setIncludeAlignment(false);
       worksheet.getRange("A1").setStyle(style);
       boolean includeAlignment = style.getIncludeAlignment();
       
      Returns:
      true if alignment-related properties are included in the style; otherwise, false.
    • setIncludeAlignment

      void setIncludeAlignment(boolean value)
      Sets whether the style includes the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties.

      Use this method to control whether alignment-related settings participate in the style when the style is applied.

      
       IStyle style = workbook.getStyles().add("alignmentStyle");
       style.setHorizontalAlignment(HorizontalAlignment.Right);
       style.setIncludeAlignment(false);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties in the style; otherwise, false.
    • getIncludeBorder

      boolean getIncludeBorder()
      Gets whether the style includes the Color, ColorIndex, LineStyle, and Weight border properties.

      Use this method to determine whether border settings defined on the style are included when the style is applied.

      
       IStyle style = workbook.getStyles().add("borderStyle");
       style.getBorders().setLineStyle(BorderLineStyle.DashDot);
       style.setIncludeBorder(true);
       worksheet.getRange("A1").setStyle(style);
       boolean includeBorder = style.getIncludeBorder();
       
      Returns:
      true if border properties are included in the style; otherwise, false.
    • setIncludeBorder

      void setIncludeBorder(boolean value)
      Sets whether the style includes the Color, ColorIndex, LineStyle, and Weight border properties.

      Use this property to control whether the border settings defined on the style are included when the style is applied. See getIncludeBorder() and getBorders().

      
       IStyle style = workbook.getStyles().add("borderStyle");
       style.getBorders().setLineStyle(BorderLineStyle.DashDot);
       style.setIncludeBorder(true);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the Color, ColorIndex, LineStyle, and Weight border properties in the style; otherwise, false.
    • getIncludeFont

      boolean getIncludeFont()
      Gets whether the style includes the Bold, Color, ColorIndex, FontStyle, Italic, Name, OutlineFont, Shadow, Size, Strikethrough, Subscript, Superscript, and Underline font properties.

      Use this method to determine whether font settings stored in the style are included when the style is applied.

      
       IStyle style = workbook.getStyles().add("fontStyle");
       style.getFont().setBold(true);
       style.getFont().setName("Arial");
       style.setIncludeFont(false);
       worksheet.getRange("A1").setStyle(style);
       boolean includeFont = style.getIncludeFont();
       
      Returns:
      true if font properties are included in the style; otherwise, false.
    • setIncludeFont

      void setIncludeFont(boolean value)
      Sets whether the style includes the Bold, Color, ColorIndex, FontStyle, Italic, Name, OutlineFont, Shadow, Size, Strikethrough, Subscript, Superscript, and Underline font properties.

      Use this property to control whether the font settings defined by this style are included when the style is applied to a range.

      
       IStyle style = workbook.getStyles().add("fontStyle");
       style.getFont().setBold(true);
       style.getFont().setName("Arial");
       style.setIncludeFont(false);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the font properties in the style; otherwise, false.
    • getIncludeNumber

      boolean getIncludeNumber()
      Gets whether the style includes the NumberFormat property.

      Use this method to determine whether the number format stored in the style is included when the style is applied.

      
       IStyle style = workbook.getStyles().add("numberStyle");
       style.setNumberFormat("$#,##0.00");
       style.setIncludeNumber(true);
       worksheet.getRange("A1").setStyle(style);
       boolean includeNumber = style.getIncludeNumber();
       
      Returns:
      true if the NumberFormat property is included in the style; otherwise, false.
    • setIncludeNumber

      void setIncludeNumber(boolean value)
      Sets whether the style includes the NumberFormat property.

      Use this method to control whether the number format defined by this style is included when the style is applied to a range.

      
       IStyle style = workbook.getStyles().add("numberStyle");
       style.setNumberFormat("$#,##0.00");
       style.setIncludeNumber(true);
       worksheet.getRange("A1").setValue(100);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the NumberFormat property in the style; otherwise, false.
    • getIncludePatterns

      boolean getIncludePatterns()
      Gets whether the style includes the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.

      Use this method to determine whether interior pattern settings are included when the style is applied.

      
       IStyle style = workbook.getStyles().add("patternStyle");
       style.getInterior().setPattern(Pattern.Gray50);
       style.getInterior().setPatternColor(Color.GetBlue());
       style.setIncludePatterns(true);
       worksheet.getRange("A1").setStyle(style);
       boolean includePatterns = style.getIncludePatterns();
       
      Returns:
      true if pattern-related interior properties are included in the style; otherwise, false.
    • setIncludePatterns

      void setIncludePatterns(boolean value)
      Sets whether the style includes the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties.

      Use this property to control whether the pattern-related settings from the style's IInterior are applied when the style is assigned to a range.

      
       IStyle style = workbook.getStyles().add("patternStyle");
       style.getInterior().setPattern(Pattern.Gray50);
       style.getInterior().setPatternColor(Color.GetBlue());
       style.setIncludePatterns(true);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties in the style; otherwise, false.
    • getIncludeProtection

      boolean getIncludeProtection()
      Gets whether the style includes the FormulaHidden and Locked properties.

      Use this method to determine whether the protection-related settings defined by the style participate when the style is applied.

      
       IStyle style = workbook.getStyles().add("protectionStyle");
       style.setLocked(true);
       style.setFormulaHidden(true);
       style.setIncludeProtection(false);
       worksheet.getRange("A1").setStyle(style);
       boolean includeProtection = style.getIncludeProtection();
       
      Returns:
      true if FormulaHidden and Locked are included in the style; otherwise, false.
    • setIncludeProtection

      void setIncludeProtection(boolean value)
      Sets whether the style includes the FormulaHidden and Locked properties.

      Use this property to control whether the protection settings defined by setFormulaHidden(boolean) and setLocked(boolean) are included in the style.

      
       IStyle style = workbook.getStyles().add("protectionStyle");
       style.setLocked(true);
       style.setFormulaHidden(true);
       style.setIncludeProtection(false);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to include the FormulaHidden and Locked properties in the style; otherwise, false.
    • getIndentLevel

      int getIndentLevel()
      Gets the indent level for the style.

      Use this method to retrieve the indentation setting stored in the style.

      
       IStyle style = workbook.getStyles().add("indentStyle");
       style.setIndentLevel(2);
       worksheet.getRange("A1").setStyle(style);
       int indentLevel = style.getIndentLevel();
       
      Returns:
      The indent level defined for the style.
    • setIndentLevel

      void setIndentLevel(int value)
      Sets the indent level for the style.

      Use this method to define the indentation applied to cell content when this style is assigned to a cell or range. To make the indentation part of the named style, ensure the alignment settings are included in the style.

      
       IStyle style = workbook.getStyles().add("indentStyle");
       style.setIndentLevel(2);
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - The indent level for the style.
    • getInterior

      IInterior getInterior()
      Returns an IInterior object that represents this style's fill formatting.

      Use this method to access fill and pattern settings such as background color and pattern style for the style.

      
       IStyle style = workbook.getStyles().add("filledStyle");
       style.getInterior().setPattern(Pattern.Solid);
       worksheet.getRange("A1").setStyle(style);
       IInterior interior = style.getInterior();
       
      Returns:
      The interior object for the style.
    • getLocked

      boolean getLocked()
      Gets whether the object is locked; false if the object can be modified when the sheet is protected.

      Use this method to determine whether cells that use the style are locked when worksheet protection is enabled.

      
       IStyle style = workbook.getStyles().add("lockedStyle");
       style.setLocked(true);
       worksheet.getRange("A1").setStyle(style);
       boolean locked = style.getLocked();
       
      Returns:
      true if the object is locked; otherwise, false.
    • setLocked

      void setLocked(boolean value)
      Sets whether the object is locked; false if the object can be modified when the sheet is protected.

      Use this method to control the locked setting stored in the style. When this style is applied to a cell or range, the locked state takes effect when worksheet protection is enabled.

      
       IStyle style = workbook.getStyles().add("lockedStyle");
       style.setLocked(true);
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to lock cells that use this style when the worksheet is protected; otherwise, false.
    • getName

      String getName()
      Returns the name of the object.

      Use this method to get the name of the named style stored in the workbook.

      
       IStyle style = workbook.getStyles().add("HeaderStyle");
       worksheet.getRange("A1").setStyle(style);
       String styleName = style.getName();
       
      Returns:
      The name of the style.
    • getNumberFormat

      String getNumberFormat()
      Gets the format code for the object as a string in the language of the user.

      Use this method to retrieve the number format code stored in the style.

      
       IStyle style = workbook.getStyles().add("currencyStyle");
       style.setNumberFormat("$#,##0.00");
       worksheet.getRange("A1").setStyle(style);
       String numberFormat = style.getNumberFormat();
       
      Returns:
      The number format code stored in the style.
    • setNumberFormat

      void setNumberFormat(String value)
      Sets the format code for the object as a string in the language of the user.

      Use this method to define the number format stored in the style. After the style is applied to a range, numeric values in that range are displayed according to the specified format code.

      
       IStyle style = workbook.getStyles().add("currencyStyle");
       style.setNumberFormat("$#,##0.00");
       worksheet.getRange("A1").setValue(12.5);
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - The format code to apply as a string in the language of the user.
    • getOrientation

      int getOrientation()
      Gets the text orientation. Can be an integer value from -90 to 90 degrees.

      Use this method to retrieve the text rotation stored in the style.

      
       IStyle style = workbook.getStyles().add("angledStyle");
       style.setOrientation(45);
       worksheet.getRange("A1").setStyle(style);
       int orientation = style.getOrientation();
       
      Returns:
      The text orientation, in degrees.
    • setOrientation

      void setOrientation(int value)
      Sets the text orientation. Can be an integer value from -90 to 90 degrees.

      Use positive values to rotate text upward and negative values to rotate text downward.

      
       IStyle style = workbook.getStyles().add("angledStyle");
       style.setOrientation(45);
       worksheet.getRange("A1").setValue("Quarterly Sales");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - The text orientation, in degrees. Valid values range from -90 to 90.
    • getShrinkToFit

      boolean getShrinkToFit()
      Gets whether the text automatically shrinks to fit in the available column width.

      Use this method to determine whether cells that use the style shrink text to fit the available column width.

      
       IStyle style = workbook.getStyles().add("shrinkStyle");
       style.setShrinkToFit(true);
       worksheet.getRange("A1").setStyle(style);
       boolean shrinkToFit = style.getShrinkToFit();
       
      Returns:
      true if shrink-to-fit is enabled; otherwise, false.
    • setShrinkToFit

      void setShrinkToFit(boolean value)
      Sets whether the text automatically shrinks to fit in the available column width.

      Use this property on a style before applying the style to a range. Set the value to true to enable shrink-to-fit behavior, or false to keep the original font size.

      
       IStyle style = workbook.getStyles().add("shrinkStyle");
       style.setShrinkToFit(true);
       worksheet.getRange("A1").setValue("Document Solutions For Excel");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to automatically shrink text to fit the available column width; otherwise, false.
    • getVerticalAlignment

      VerticalAlignment getVerticalAlignment()
      Gets the vertical alignment of the specified object.

      Use this method to retrieve the vertical alignment stored in the style.

      
       IStyle style = workbook.getStyles().add("topStyle");
       style.setVerticalAlignment(VerticalAlignment.Top);
       worksheet.getRange("A1").setStyle(style);
       VerticalAlignment alignment = style.getVerticalAlignment();
       
      Returns:
      The vertical alignment defined for the style.
    • setVerticalAlignment

      void setVerticalAlignment(VerticalAlignment value)
      Sets the vertical alignment for this style.

      Use this method to control how content is positioned vertically when this style is applied.

      
       IStyle style = workbook.getStyles().add("topStyle");
       style.setVerticalAlignment(VerticalAlignment.Top);
       worksheet.getRange("A1").setValue("Name");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - The vertical alignment to apply.
    • getWrapText

      boolean getWrapText()
      Gets whether text wraps automatically.

      Use this method to determine whether text in cells that use the style is wrapped.

      
       IStyle style = workbook.getStyles().add("wrapStyle");
       style.setWrapText(true);
       worksheet.getRange("A1").setStyle(style);
       boolean wrapText = style.getWrapText();
       
      Returns:
      true if text wrapping is enabled; otherwise, false.
    • setWrapText

      void setWrapText(boolean value)
      Sets whether text wraps automatically.

      Use this method to control whether text in cells that use this style is wrapped. The wrap text setting is part of the alignment-related style properties.

      
       IStyle style = workbook.getStyles().add("wrapStyle");
       style.setWrapText(true);
       worksheet.getRange("A1").setValue("Long text that should wrap in the cell");
       worksheet.getRange("A1").setStyle(style);
       
      Parameters:
      value - true to enable text wrapping; otherwise, false.
    • delete

      boolean delete()
      Deletes this style.

      Use this method to remove a custom named style from the workbook. Built-in styles cannot be deleted.

      
       IStyle style = workbook.getStyles().add("TemporaryStyle");
       worksheet.getRange("A1").setStyle(style);
       boolean deleted = style.delete();
       
      Returns:
      true if the style is successfully deleted; otherwise, false.
    • fromJson

      void fromJson(String json)
      Generates the named style from the JSON string.

      Use this method to load a named style definition from JSON, such as a string previously generated by toJson().

      
       IStyle sourceStyle = workbook.getStyles().add("PriceStyle");
       sourceStyle.setIncludeNumber(true);
       sourceStyle.setNumberFormat("$#,##0.00");
      
       IStyle copiedStyle = workbook.getStyles().add("CopiedPriceStyle");
       copiedStyle.fromJson(sourceStyle.toJson());
       worksheet.getRange("A1").setStyle(copiedStyle);
       
      Parameters:
      json - The JSON string that contains the named style definition.
    • toJson

      String toJson()
      Generates a JSON string from the named style.

      Use this method to serialize a named style to JSON so that it can be stored or used later with fromJson(String).

      
       IStyle style = workbook.getStyles().add("PriceStyle");
       style.setIncludeNumber(true);
       style.setNumberFormat("$#,##0.00");
       worksheet.getRange("A1").setStyle(style);
       String json = style.toJson();
       
      Returns:
      The JSON string that contains the named style definition.