aspose.cells

Class Style

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:

$workbook = new cells\Workbook();
$cell = $workbook->getWorksheets()->get(0)->getCells()->get("A1");
$style1 = $cell->getStyle();
$style1->getFont()->setName("Times New Roman");
$style1->getFont()->setColor(cells\Color::getBlue());
$cell->setStyle($style1);

Constructor Summary
Style()
Initializes a new instance of the Style class.
 
Property Getters/Setters Summary
functiongetBackgroundArgbColor()
function
           Gets and sets the background color with a 32-bit ARGB value.
functiongetBackgroundColor()
function
           Gets or sets a style's background color.
functiongetBackgroundThemeColor()
function
           Gets and sets the background theme color.
functiongetBorders()
Gets the BorderCollection of the style.
functiongetCultureCustom()
function
           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.
functiongetCustom()
function
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.
functiongetFont()
Gets a Font object.
functiongetForegroundArgbColor()
function
           Gets and sets the foreground color with a 32-bit ARGB value.
functiongetForegroundColor()
function
           Gets or sets a style's foreground color.
functiongetForegroundThemeColor()
function
           Gets and sets the foreground theme color.
functionhasBorders()
Checks whether there are borders have been set for the style.
functiongetHorizontalAlignment()
function
           Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
functiongetIndentLevel()
function
           Represents the indent level for the cell or range. Can only be an integer from 0 to 250.
functiongetInvariantCustom()
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.
functionisAlignmentApplied()
function
           Indicate whether the alignment formatting should be applied.
functionisBorderApplied()
function
           Indicate whether the border formatting should be applied.
functionisDateTime()
Indicates whether the number format is a date format.
functionisFillApplied()
function
           Indicate whether the fill formatting should be applied.
functionisFontApplied()
function
           Indicate whether the font formatting should be applied.
functionisFormulaHidden()
function
           Represents if the formula will be hidden when the worksheet is protected.
functionisGradient()
function
           Indicates whether the cell shading is a gradient pattern.
functionisJustifyDistributed()
function
           Indicates if the cells justified or distributed alignment should be used on the last line of text.
functionisLocked()
function
setLocked(value)
           Gets or sets a value indicating whether a cell can be modified or not.
functionisNumberFormatApplied()
function
           Indicate whether the number formatting should be applied.
functionisPercent()
Indicates whether the number format is a percent format.
functionisProtectionApplied()
function
           Indicate whether the protection formatting should be applied.
functionisTextWrapped()
function
           Gets or sets a value indicating whether the text within a cell is wrapped.
functiongetName()
function
setName(value)
           Gets or sets the name of the style.
functiongetNumber()
function
setNumber(value)
           Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions.
functiongetParentStyle()
Gets the parent style of this style.
functiongetPattern()
function
setPattern(value)
           Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.
functiongetQuotePrefix()
function
           Indicates whether the cell's value starts with single quote mark.
functiongetRotationAngle()
function
           Represents text rotation angle.
functiongetShrinkToFit()
function
           Represents if text automatically shrinks to fit in the available column width.
functiongetTextDirection()
function
           Represents text reading order. The value of the property is TextDirectionType integer constant.
functiongetVerticalAlignment()
function
           Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
 
Method Summary
functioncopy(style)
Copies data from another style object
functionequals(obj)
Determines whether two Style instances are equal.
functiongetTwoColorGradient()
Get the two-color gradient setting.
functiongetTwoColorGradientSetting()
Get the two-color gradient setting.
functionhashCode()
Serves as a hash function for a Style object.
functionisModified(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.
functionsetBorder(borderType, borderStyle, borderColor)
Sets the borders of the style.
functionsetBorder(borderType, borderStyle, borderColor)
Sets the borders of the style.
functionsetCustom(custom, builtinPreference)
Sets the Custom number format string of a cell.
functionsetPatternColor(pattern, color1, color2)
Sets the background color.
functionsetTwoColorGradient(color1, color2, gradientStyleType, variant)
Sets the specified fill to a two-color gradient.
functiontoJson()
Convert Style to JSON struct data.
functionupdate()
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

        function 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 

        function getBackgroundThemeColor() / function 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 

        function getForegroundThemeColor() / function 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 

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

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

        function getBackgroundColor() / function 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 : Number 

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

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

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

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

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

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

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

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

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

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

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

        function getIndentLevel() / function 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 

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

        function getRotationAngle() / function 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 : Number 

        function getHorizontalAlignment() / function 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 : Number 

        function getVerticalAlignment() / function 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 

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

        function getNumber() / function 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 

        function isLocked() / function 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 

        function getCustom() / function 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 

        function getCultureCustom() / function 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 

        function 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 

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

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

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

        function isJustifyDistributed() / function 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 

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

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

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

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

      • setTwoColorGradient

        function 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: Number - A GradientStyleType value. Gradient shading style.
        variant: Number - 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

        function 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

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

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

        function setPatternColor(pattern, color1, color2)
        Sets the background color.
        Parameters:
        pattern: Number - 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

        function 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

        function 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

        function 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: Number - A StyleModifyFlag value. Style modified flags
        Returns:
        true if the specified properties have been modified
      • equals

        function 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

        function 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

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

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

        function 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.