Methods

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

Example

//First method
var excel = new aspose.cells.Workbook();
var style = excel.createStyle();
style.getFont().setName("Times New Roman");
style.getFont().setColor(aspose.cells.Color.getBlue());
for (var i = 0; i < 100; i++)
{
excel.getWorksheets().get(0).getCells().get(0, i).setStyle(style);
}
//Second method
var style1 = excel.getWorksheets().get(0).getCells().get("A1").getStyle();
style1.getFont().setName("Times New Roman");
style1.getFont().setColor(aspose.cells.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.

Methods

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.

Parameter

Name Type Optional Description

style

Style

 

Source Style object

equals(obj) → boolean

Determines whether two Style instances are equal.

Parameter

Name Type Optional Description

obj

Object

 

The Style object to compare with the current Style object.

Returns

boolean true if the specified Object is equal to the current Object; otherwise, false.

getBackgroundArgbColor()

Gets and sets the background color with a 32-bit ARGB value.

getBackgroundColor()

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.

getBackgroundThemeColor()

Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned.

getBorders()

Gets the BorderCollection of the style.

getCultureCustom()

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.

getCustom()

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.

getFont()

Gets a Font object.

getForegroundArgbColor()

Gets and sets the foreground color with a 32-bit ARGB value.

getForegroundColor()

Gets or sets a style's foreground color. It means no color setting if Color.Empty is returned.

getForegroundThemeColor()

Gets and sets the foreground theme color. If the foreground color is not a theme color, NULL will be returned.

getHorizontalAlignment()

Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

getIndentLevel()

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.

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.

getName()

Gets or sets the name of the style.

getNumber()

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 String0GeneralGeneral1Decimal02Decimal0.003Decimal#,##04Decimal#,##0.005Currency$#,##0_);($#,##0)6Currency$#,##0_);Red7Currency$#,##0.00_);($#,##0.00)8Currency$#,##0.00_);Red9Percentage0%10Percentage0.00%11Scientific0.00E+0012Fraction# ?/?13Fraction# ??/??14Datem/d/yyyy15Dated-mmm-yy16Dated-mmm17Datemmm-yy18Timeh:mm AM/PM19Timeh:mm:ss AM/PM20Timeh:mm21Timeh:mm:ss22Timem/d/yyyy h:mm37Accounting#,##0_);(#,##0)38Accounting#,##0_);Red39Accounting#,##0.00_);(#,##0.00)40Accounting#,##0.00_);Red41Accounting_(* #,##0_);(* (#,##0);(* "-");(@)42Currency($* #,##0_);($* (#,##0);($* "-");(@)43Accounting(* #,##0.00_);(* (#,##0.00);(* "-"??);(@)44Currency($* #,##0.00_);($* (#,##0.00);($* "-"??);(@_)45Timemm:ss46Time[h]:mm:ss47Timemm:ss.048Scientific##0.0E+049Text@

getParentStyle()

Gets the parent style of this style.

getPattern()

Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.

getQuotePrefix()

Indicates whether the cell's value starts with single quote mark.

getRotationAngle()

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.

getShrinkToFit()

Represents if text automatically shrinks to fit in the available column width.

getTextDirection()

Represents text reading order. The value of the property is TextDirectionType integer constant.

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.@return {Object[]} Returns all setting about two-color gradient [0] : Color1 [1] : Color2 [2] : GradientStyleType [3] : Variant

getTwoColorGradientSetting()

Get the two-color gradient setting.

getVerticalAlignment()

Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

hasBorders()

Checks whether there are borders have been set for the style.

hashCode()

Serves as a hash function for a Style object. This method is only for internal use.@return {Number} A hash code for the current Object.

isAlignmentApplied()

Indicate whether the alignment formatting should be applied. Only for named style.

isBorderApplied()

Indicate whether the border formatting should be applied. Only for named style.

isDateTime()

Indicates whether the number format is a date format.

isFillApplied()

Indicate whether the fill formatting should be applied. Only for named style.

isFontApplied()

Indicate whether the font formatting should be applied. Only for named style.

isFormulaHidden()

Represents if the formula will be hidden when the worksheet is protected.

isGradient()

Indicates whether the cell shading is a gradient pattern.

isJustifyDistributed()

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.

isLocked()

Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet is protected.

isModified(modifyFlag) → boolean

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.

Parameter

Name Type Optional Description

modifyFlag

Number

 

StyleModifyFlag

Returns

boolean true if the specified properties have been modified

isNumberFormatApplied()

Indicate whether the number formatting should be applied. Only for named style.

isPercent()

Indicates whether the number format is a percent format.

isProtectionApplied()

Indicate whether the protection formatting should be applied. Only for named style.

isTextWrapped()

Gets or sets a value indicating whether the text within a cell is wrapped.

setAlignmentApplied()

Indicate whether the alignment formatting should be applied. Only for named style.

setBackgroundArgbColor()

Gets and sets the background color with a 32-bit ARGB value.

setBackgroundColor()

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.

setBackgroundThemeColor()

Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned.

setBorder(borderType, borderStyle, borderColor) → boolean

Sets the borders of the style.

Parameters

Name Type Optional Description

borderType

Number

 

BorderType

borderStyle

Number

 

CellBorderType

borderColor

Color

 

The color of the border.

Returns

boolean Whether current border settings have been changed.

setBorder(borderType, borderStyle, borderColor) → boolean

Sets the borders of the style.

Parameters

Name Type Optional Description

borderType

Number

 

BorderType

borderStyle

Number

 

CellBorderType

borderColor

CellsColor

 

The color of the border.

Returns

boolean Whether current border settings have been changed.

setBorderApplied()

Indicate whether the border formatting should be applied. Only for named style.

setCultureCustom()

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.

setCustom()

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.

setCustom(custom, builtinPreference)

Sets the Custom number format string of a cell.

Parameters

Name Type Optional Description

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.

setFillApplied()

Indicate whether the fill formatting should be applied. Only for named style.

setFontApplied()

Indicate whether the font formatting should be applied. Only for named style.

setForegroundArgbColor()

Gets and sets the foreground color with a 32-bit ARGB value.

setForegroundColor()

Gets or sets a style's foreground color. It means no color setting if Color.Empty is returned.

setForegroundThemeColor()

Gets and sets the foreground theme color. If the foreground color is not a theme color, NULL will be returned.

setFormulaHidden()

Represents if the formula will be hidden when the worksheet is protected.

setGradient()

Indicates whether the cell shading is a gradient pattern.

setHorizontalAlignment()

Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

setIndentLevel()

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.

setJustifyDistributed()

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.

setLocked()

Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet is protected.

setName()

Gets or sets the name of the style.

setNumber()

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 String0GeneralGeneral1Decimal02Decimal0.003Decimal#,##04Decimal#,##0.005Currency$#,##0_);($#,##0)6Currency$#,##0_);Red7Currency$#,##0.00_);($#,##0.00)8Currency$#,##0.00_);Red9Percentage0%10Percentage0.00%11Scientific0.00E+0012Fraction# ?/?13Fraction# ??/??14Datem/d/yyyy15Dated-mmm-yy16Dated-mmm17Datemmm-yy18Timeh:mm AM/PM19Timeh:mm:ss AM/PM20Timeh:mm21Timeh:mm:ss22Timem/d/yyyy h:mm37Accounting#,##0_);(#,##0)38Accounting#,##0_);Red39Accounting#,##0.00_);(#,##0.00)40Accounting#,##0.00_);Red41Accounting_(* #,##0_);(* (#,##0);(* "-");(@)42Currency($* #,##0_);($* (#,##0);($* "-");(@)43Accounting(* #,##0.00_);(* (#,##0.00);(* "-"??);(@)44Currency($* #,##0.00_);($* (#,##0.00);($* "-"??);(@_)45Timemm:ss46Time[h]:mm:ss47Timemm:ss.048Scientific##0.0E+049Text@

setNumberFormatApplied()

Indicate whether the number formatting should be applied. Only for named style.

setPattern()

Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.

setPatternColor(pattern, color1, color2)

Sets the background color.

Parameters

Name Type Optional Description

pattern

Number

 

BackgroundType

color1

Color

 

The foreground color.

color2

Color

 

The background color. Only works when pattern is not BackgroundType.None and BackgroundType.Solid.

setProtectionApplied()

Indicate whether the protection formatting should be applied. Only for named style.

setQuotePrefix()

Indicates whether the cell's value starts with single quote mark.

setRotationAngle()

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.

setShrinkToFit()

Represents if text automatically shrinks to fit in the available column width.

setTextDirection()

Represents text reading order. The value of the property is TextDirectionType integer constant.

setTextWrapped()

Gets or sets a value indicating whether the text within a cell is wrapped.

setTwoColorGradient(color1, color2, gradientStyleType, variant)

Sets the specified fill to a two-color gradient.

Parameters

Name Type Optional Description

color1

Color

 

One gradient color.

color2

Color

 

Two gradient color.

gradientStyleType

Number

 

GradientStyleType

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.

setVerticalAlignment()

Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.

toJson() → String

Convert Style to JSON struct data.

Returns

String 

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.