asposecells.api

Represents display style of excel document,such as font,color,alignment,border,etc. The Style object contains all style attributes (font, number format, alignment, and so on) as properties.

Example:

# First method
excel = Workbook()
style = excel.createStyle()
style.getFont().setName("Times New Roman")
style.getFont().setColor(Color.getBlue())
for i in range(0, 100):
    excel.getWorksheets().get(0).getCells().get(0, i).setStyle(style)

# Second method
style1 = excel.getWorksheets().get(0).getCells().get("A1").getStyle()
style1.getFont().setName("Times New Roman")
style1.getFont().setColor(Color.getBlue())
excel.getWorksheets().get(0).getCells().get("A1").setStyle(style1)

# First method is a fast and efficient way to change several cell-formatting properties on multiple cells at the same time.
# If you want to change a single cell's style properties, second method can be used.

Constructor Summary
Style()
Initializes a new instance of the Style class.
 
Property Getters/Setters Summary
methodgetBackgroundArgbColor()
method
           Gets and sets the background color with a 32-bit ARGB value.
methodgetBackgroundColor()
method
           Gets or sets a style's background color.
methodgetBackgroundThemeColor()
method
           Gets and sets the background theme color.
methodgetBorders()
Gets the BorderCollection of the style.
methodgetCultureCustom()
method
           Gets and sets the culture-dependent pattern string for number format. If no number format has been set for this object, null will be returned. If number format is builtin, the pattern string corresponding to the builtin number will be returned.
methodgetCustom()
method
setCustom(value)
           Represents the custom number format string of this style object. If the custom number format is not set(For example, the number format is builtin), "" will be returned.
methodgetFont()
Gets a Font object.
methodgetForegroundArgbColor()
method
           Gets and sets the foreground color with a 32-bit ARGB value.
methodgetForegroundColor()
method
           Gets or sets a style's foreground color.
methodgetForegroundThemeColor()
method
           Gets and sets the foreground theme color.
methodhasBorders()
Checks whether there are borders have been set for the style.
methodgetHorizontalAlignment()
method
           Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
methodgetIndentLevel()
method
           Represents the indent level for the cell or range. Can only be an integer from 0 to 250.
methodgetInvariantCustom()
Gets the culture-independent pattern string for number format. If no number format has been set for this object, null will be returned. If number format is builtin, the pattern string corresponding to the builtin number will be returned.
methodisAlignmentApplied()
method
           Indicate whether the alignment formatting should be applied.
methodisBorderApplied()
method
           Indicate whether the border formatting should be applied.
methodisDateTime()
Indicates whether the number format is a date format.
methodisFillApplied()
method
           Indicate whether the fill formatting should be applied.
methodisFontApplied()
method
           Indicate whether the font formatting should be applied.
methodisFormulaHidden()
method
           Represents if the formula will be hidden when the worksheet is protected.
methodisGradient()
method
           Indicates whether the cell shading is a gradient pattern.
methodisJustifyDistributed()
method
           Indicates if the cells justified or distributed alignment should be used on the last line of text.
methodisLocked()
method
setLocked(value)
           Gets or sets a value indicating whether a cell can be modified or not.
methodisNumberFormatApplied()
method
           Indicate whether the number formatting should be applied.
methodisPercent()
Indicates whether the number format is a percent format.
methodisProtectionApplied()
method
           Indicate whether the protection formatting should be applied.
methodisTextWrapped()
method
           Gets or sets a value indicating whether the text within a cell is wrapped.
methodgetName()
method
setName(value)
           Gets or sets the name of the style.
methodgetNumber()
method
setNumber(value)
           Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions.
methodgetParentStyle()
Gets the parent style of this style.
methodgetPattern()
method
setPattern(value)
           Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.
methodgetQuotePrefix()
method
           Indicates whether the cell's value starts with single quote mark.
methodgetRotationAngle()
method
           Represents text rotation angle.
methodgetShrinkToFit()
method
           Represents if text automatically shrinks to fit in the available column width.
methodgetTextDirection()
method
           Represents text reading order. The value of the property is TextDirectionType integer constant.
methodgetVerticalAlignment()
method
           Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
 
Method Summary
methodcopy(style)
Copies data from another style object
methodequals(obj)
Determines whether two Style instances are equal.
methodgetTwoColorGradient()
Get the two-color gradient setting.
methodgetTwoColorGradientSetting()
Get the two-color gradient setting.
methodhashCode()
Serves as a hash function for a Style object.
methodisModified(modifyFlag)
Checks whether the specified properties of the style have been modified. Used for style of ConditionalFormattings to check whether the specified properties of this style should be used when applying the ConditionalFormattings on a cell.
methodsetBorder(borderType, borderStyle, borderColor)
Sets the borders of the style.
methodsetBorder(borderType, borderStyle, borderColor)
Sets the borders of the style.
methodsetCustom(custom, builtinPreference)
Sets the Custom number format string of a cell.
methodsetPatternColor(pattern, color1, color2)
Sets the background color.
methodsetTwoColorGradient(color1, color2, gradientStyleType, variant)
Sets the specified fill to a two-color gradient.
methodtoJson()
Convert Style to JSON struct data.
methodupdate()
Apply the named style to the styles of the cells which use this named style. It works like clicking the "ok" button after you finished modifying the style. Only applies for named style.
 

    • Constructor Detail

      • Style

        Style()
        Initializes a new instance of the Style class. NOTE: This constructor is now obsolete. Instead, please use CellsFactory.CreateStyle() method. This property will be removed 6 months later since October 2016. Aspose apologizes for any inconvenience you may have experienced.
    • Property Getters/Setters Detail

      • getBackgroundThemeColor/setBackgroundThemeColor : ThemeColor 

        ThemeColor getBackgroundThemeColor() / setBackgroundThemeColor(value)
        
        Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned.
      • getForegroundThemeColor/setForegroundThemeColor : ThemeColor 

        ThemeColor getForegroundThemeColor() / setForegroundThemeColor(value)
        
        Gets and sets the foreground theme color. If the foreground color is not a theme color, NULL will be returned.
      • getName/setName : String 

        String getName() / setName(value)
        
        Gets or sets the name of the style.
      • getPattern/setPattern : int 

        int getPattern() / setPattern(value)
        
        Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.
      • getBackgroundColor/setBackgroundColor : Color 

        Color getBackgroundColor() / setBackgroundColor(value)
        
        Gets or sets a style's background color. If you want to set a cell's color, please use Style.ForegroundColor property. Only if the cell style pattern is other than none or solid, this property will take effect.
      • getBackgroundArgbColor/setBackgroundArgbColor : int 

        int getBackgroundArgbColor() / setBackgroundArgbColor(value)
        
        Gets and sets the background color with a 32-bit ARGB value.
      • getForegroundColor/setForegroundColor : Color 

        Color getForegroundColor() / setForegroundColor(value)
        
        Gets or sets a style's foreground color. It means no color setting if Color.Empty is returned.
      • getForegroundArgbColor/setForegroundArgbColor : int 

        int getForegroundArgbColor() / setForegroundArgbColor(value)
        
        Gets and sets the foreground color with a 32-bit ARGB value.
      • hasBorders : boolean 

        boolean hasBorders()
        
        Checks whether there are borders have been set for the style.
      • getParentStyle : Style 

        Style getParentStyle()
        
        Gets the parent style of this style.
      • isNumberFormatApplied/setNumberFormatApplied : boolean 

        boolean isNumberFormatApplied() / setNumberFormatApplied(value)
        
        Indicate whether the number formatting should be applied. Only for named style.
      • isFontApplied/setFontApplied : boolean 

        boolean isFontApplied() / setFontApplied(value)
        
        Indicate whether the font formatting should be applied. Only for named style.
      • isAlignmentApplied/setAlignmentApplied : boolean 

        boolean isAlignmentApplied() / setAlignmentApplied(value)
        
        Indicate whether the alignment formatting should be applied. Only for named style.
      • isBorderApplied/setBorderApplied : boolean 

        boolean isBorderApplied() / setBorderApplied(value)
        
        Indicate whether the border formatting should be applied. Only for named style.
      • isFillApplied/setFillApplied : boolean 

        boolean isFillApplied() / setFillApplied(value)
        
        Indicate whether the fill formatting should be applied. Only for named style.
      • isProtectionApplied/setProtectionApplied : boolean 

        boolean isProtectionApplied() / setProtectionApplied(value)
        
        Indicate whether the protection formatting should be applied. Only for named style.
      • getIndentLevel/setIndentLevel : int 

        int getIndentLevel() / setIndentLevel(value)
        
        Represents the indent level for the cell or range. Can only be an integer from 0 to 250. If text horizontal alignment type is set to value other than left or right, indent level will be reset to zero.
      • getFont : Font 

        Font getFont()
        
        Gets a Font object.
      • getRotationAngle/setRotationAngle : int 

        int getRotationAngle() / setRotationAngle(value)
        
        Represents text rotation angle.

        0: Not rotated.

        255: Top to Bottom.

        -90: Downward.

        90: Upward.

        You can set 255 or value ranged from -90 to 90.
      • getHorizontalAlignment/setHorizontalAlignment : int 

        int getHorizontalAlignment() / setHorizontalAlignment(value)
        
        Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
      • getVerticalAlignment/setVerticalAlignment : int 

        int getVerticalAlignment() / setVerticalAlignment(value)
        
        Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
      • isTextWrapped/setTextWrapped : boolean 

        boolean isTextWrapped() / setTextWrapped(value)
        
        Gets or sets a value indicating whether the text within a cell is wrapped.
      • getNumber/setNumber : int 

        int getNumber() / setNumber(value)
        
        Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions. For example, the formatting patterns represented by numbers for en_US region:
        ValueTypeFormat String
        0GeneralGeneral
        1Decimal0
        2Decimal0.00
        3Decimal#,##0
        4Decimal#,##0.00
        5Currency$#,##0_);($#,##0)
        6Currency$#,##0_);[Red]($#,##0)
        7Currency$#,##0.00_);($#,##0.00)
        8Currency$#,##0.00_);[Red]($#,##0.00)
        9Percentage0%
        10Percentage0.00%
        11Scientific0.00E+00
        12Fraction# ?/?
        13Fraction# ??/??
        14Datem/d/yyyy
        15Dated-mmm-yy
        16Dated-mmm
        17Datemmm-yy
        18Timeh:mm AM/PM
        19Timeh:mm:ss AM/PM
        20Timeh:mm
        21Timeh:mm:ss
        22Timem/d/yyyy h:mm
        37Accounting#,##0_);(#,##0)
        38Accounting#,##0_);[Red](#,##0)
        39Accounting#,##0.00_);(#,##0.00)
        40Accounting#,##0.00_);[Red](#,##0.00)
        41Accounting_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)
        42Currency_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)
        43Accounting_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)
        44Currency_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)
        45Timemm:ss
        46Time[h]:mm:ss
        47Timemm:ss.0
        48Scientific##0.0E+0
        49Text@
      • isLocked/setLocked : boolean 

        boolean isLocked() / setLocked(value)
        
        Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet is protected.
      • getCustom/setCustom : String 

        String getCustom() / setCustom(value)
        
        Represents the custom number format string of this style object. If the custom number format is not set(For example, the number format is builtin), "" will be returned. The returned custom string is culture-independent.
      • getCultureCustom/setCultureCustom : String 

        String getCultureCustom() / setCultureCustom(value)
        
        Gets and sets the culture-dependent pattern string for number format. If no number format has been set for this object, null will be returned. If number format is builtin, the pattern string corresponding to the builtin number will be returned. For builtin number format, both the pattern content(such as, one builtin date format is "m/d/y" for some locales, but for some other locales it becomes "d/m/y") and the format specifier(such as, some locales is using character other than 'y' to represent the year part for date formatting) are culture-dependent; For user specified custom format, only format specifiers are changed according to the culture, other parts of the formatting pattern will not be modified.
      • getInvariantCustom : String 

        String getInvariantCustom()
        
        Gets the culture-independent pattern string for number format. If no number format has been set for this object, null will be returned. If number format is builtin, the pattern string corresponding to the builtin number will be returned. For builtin number formats, the returned pattern content is still culture-dependent, such as, for some locales it returns "m/d/y" and for some other locales it returns "d/m/y". The difference from CultureCustom is(that is also what culture-independent means): the format specifiers and separators are kept as standard, such as '/' will always be used as datetime separator and "y" will always be used as the "year" part no matter what other special character is used for the specific locale.
      • isFormulaHidden/setFormulaHidden : boolean 

        boolean isFormulaHidden() / setFormulaHidden(value)
        
        Represents if the formula will be hidden when the worksheet is protected.
      • getShrinkToFit/setShrinkToFit : boolean 

        boolean getShrinkToFit() / setShrinkToFit(value)
        
        Represents if text automatically shrinks to fit in the available column width.
      • getTextDirection/setTextDirection : int 

        int getTextDirection() / setTextDirection(value)
        
        Represents text reading order. The value of the property is TextDirectionType integer constant.
      • isJustifyDistributed/setJustifyDistributed : boolean 

        boolean isJustifyDistributed() / setJustifyDistributed(value)
        
        Indicates if the cells justified or distributed alignment should be used on the last line of text. This is typical for East Asian alignments but not typical in other contexts.
      • getQuotePrefix/setQuotePrefix : boolean 

        boolean getQuotePrefix() / setQuotePrefix(value)
        
        Indicates whether the cell's value starts with single quote mark.
      • isGradient/setGradient : boolean 

        boolean isGradient() / setGradient(value)
        
        Indicates whether the cell shading is a gradient pattern.
      • isPercent : boolean 

        boolean isPercent()
        
        Indicates whether the number format is a percent format.
      • isDateTime : boolean 

        boolean isDateTime()
        
        Indicates whether the number format is a date format.
    • Method Detail

      • setTwoColorGradient

         setTwoColorGradient(color1, color2, gradientStyleType, variant)
        Sets the specified fill to a two-color gradient.
        Parameters:
        color1: Color - One gradient color.
        color2: Color - Two gradient color.
        gradientStyleType: int - A GradientStyleType value. Gradient shading style.
        variant: int - The gradient variant. Can be a value from 1 through 4, corresponding to one of the four variants on the Gradient tab in the Fill Effects dialog box. If style is GradientStyle.FromCenter, the Variant argument can only be 1 or 2.
      • getTwoColorGradient

        Object[] getTwoColorGradient()
        Get the two-color gradient setting. If this is not gradient fill,return null; NOTE: This method is now obsolete. Instead, please use Style.GetTwoColorGradientSetting() method. This property will be removed 12 months later since December 2022. Aspose apologizes for any inconvenience you may have experienced.
        Returns:
        Returns all setting about two-color gradient [0] : Color1 [1] : Color2 [2] : GradientStyleType [3] : Variant
      • getTwoColorGradientSetting

        TwoColorGradient getTwoColorGradientSetting()
        Get the two-color gradient setting.
      • toJson

        String toJson()
        Convert Style to JSON struct data.
        Returns:
      • setPatternColor

         setPatternColor(pattern, color1, color2)
        Sets the background color.
        Parameters:
        pattern: int - A BackgroundType value. The pattern.
        color1: Color - The foreground color.
        color2: Color - The background color. Only works when pattern is not BackgroundType.None and BackgroundType.Solid.
      • copy

         copy(style)
        Copies data from another style object This method does not copy the name of the style. If you want to copy the name, please call the following codes after copying style: destStyle.Name = style.Name.
        Parameters:
        style: Style - Source Style object
      • update

         update()
        Apply the named style to the styles of the cells which use this named style. It works like clicking the "ok" button after you finished modifying the style. Only applies for named style.
      • isModified

        boolean isModified(modifyFlag)
        Checks whether the specified properties of the style have been modified. Used for style of ConditionalFormattings to check whether the specified properties of this style should be used when applying the ConditionalFormattings on a cell.
        Parameters:
        modifyFlag: int - A StyleModifyFlag value. Style modified flags
        Returns:
        true if the specified properties have been modified
      • equals

        boolean equals(obj)
        Determines whether two Style instances are equal.
        Parameters:
        obj: Object - The Style object to compare with the current Style object.
        Returns:
        true if the specified Object is equal to the current Object; otherwise, false.
      • hashCode

        int hashCode()
        Serves as a hash function for a Style object. This method is only for internal use.
        Returns:
        A hash code for the current Object.
      • setBorder

        boolean setBorder(borderType, borderStyle, borderColor)
        Sets the borders of the style.
        Parameters:
        borderType: int - A BorderType value. The border(s) to be set, can be combination of BorderType.
        borderStyle: int - A CellBorderType value. The style of the border.
        borderColor: Color - The color of the border.
        Returns:
        Whether current border settings have been changed.
      • setBorder

        boolean setBorder(borderType, borderStyle, borderColor)
        Sets the borders of the style.
        Parameters:
        borderType: int - A BorderType value. The border(s) to be set, can be combination of BorderType.
        borderStyle: int - A CellBorderType value. The style of the border.
        borderColor: CellsColor - The color of the border.
        Returns:
        Whether current border settings have been changed.
      • setCustom

         setCustom(custom, builtinPreference)
        Sets the Custom number format string of a cell.
        Parameters:
        custom: String - Custom number format string, should be InvariantCulture pattern.
        builtinPreference: boolean - If given Custom number format string matches one of the built-in number formats corresponding to current regional settings, whether set the number format as built-in instead of Custom.