Class Style

Class Style

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

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.

public class Style

Inheritance

objectStyle

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

csharp
[C#]
Workbook workbook = new Workbook();

WorksheetCollection sheets = workbook.Worksheets;
Cell cell = sheets[0].Cells["A1"];
Style style =  cell.GetStyle();
style.Font.Name = "Times New Roman";
style.Font.Color = Color.Blue;
cell.SetStyle(style);

Properties

BackgroundArgbColor

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

public int BackgroundArgbColor { get; set; }

Property Value

int

BackgroundColor

Gets or sets a style’s background color.

public Color BackgroundColor { get; set; }

Property Value

Color

Remarks

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.

BackgroundThemeColor

Gets and sets the background theme color.

public ThemeColor BackgroundThemeColor { get; set; }

Property Value

ThemeColor

Remarks

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

Borders

Gets the Aspose.Cells.BorderCollection of the style.

public BorderCollection Borders { get; }

Property Value

BorderCollection

CultureCustom

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.

public string CultureCustom { get; set; }

Property Value

string

Remarks

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.

Custom

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.

public string Custom { get; set; }

Property Value

string

Remarks

The returned custom string is culture-independent.

Font

Gets a Aspose.Cells.Style.Font object.

public Font Font { get; }

Property Value

Font

ForegroundArgbColor

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

public int ForegroundArgbColor { get; set; }

Property Value

int

ForegroundColor

Gets or sets a style’s foreground color.

public Color ForegroundColor { get; set; }

Property Value

Color

Remarks

It means no color setting if Color.Empty is returned.

ForegroundThemeColor

Gets and sets the foreground theme color.

public ThemeColor ForegroundThemeColor { get; set; }

Property Value

ThemeColor

Remarks

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

HasBorders

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

public bool HasBorders { get; }

Property Value

bool

HorizontalAlignment

Gets or sets the horizontal alignment type of the text in a cell.

public TextAlignmentType HorizontalAlignment { get; set; }

Property Value

TextAlignmentType

IndentLevel

Represents the indent level for the cell or range. Can only be an integer from 0 to 250.

public int IndentLevel { get; set; }

Property Value

int

Remarks

If text horizontal alignment type is set to value other than left or right, indent level will be reset to zero.

InvariantCustom

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.

public string InvariantCustom { get; }

Property Value

string

Remarks

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 Aspose.Cells.Style.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.

IsAlignmentApplied

Indicate whether the alignment formatting should be applied.

public bool IsAlignmentApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsBorderApplied

Indicate whether the border formatting should be applied.

public bool IsBorderApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsDateTime

Indicates whether the number format is a date format.

public bool IsDateTime { get; }

Property Value

bool

IsFillApplied

Indicate whether the fill formatting should be applied.

public bool IsFillApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsFontApplied

Indicate whether the font formatting should be applied.

public bool IsFontApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsFormulaHidden

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

public bool IsFormulaHidden { get; set; }

Property Value

bool

IsGradient

Indicates whether the cell shading is a gradient pattern.

public bool IsGradient { get; set; }

Property Value

bool

IsJustifyDistributed

Indicates if the cells justified or distributed alignment should be used on the last line of text.

public bool IsJustifyDistributed { get; set; }

Property Value

bool

Remarks

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.

public bool IsLocked { get; set; }

Property Value

bool

Remarks

Locking cells has no effect unless the worksheet is protected.

IsNumberFormatApplied

Indicate whether the number formatting should be applied.

public bool IsNumberFormatApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsPercent

Indicates whether the number format is a percent format.

public bool IsPercent { get; }

Property Value

bool

IsProtectionApplied

Indicate whether the protection formatting should be applied.

public bool IsProtectionApplied { get; set; }

Property Value

bool

Remarks

Only for named style.

IsTextWrapped

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

public bool IsTextWrapped { get; set; }

Property Value

bool

Name

Gets or sets the name of the style.

public string Name { get; set; }

Property Value

string

Number

Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions.

public int Number { get; set; }

Property Value

int

Remarks

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@

ParentStyle

Gets the parent style of this style.

public Style ParentStyle { get; }

Property Value

Style

Pattern

Gets or sets the cell background pattern type.

public BackgroundType Pattern { get; set; }

Property Value

BackgroundType

QuotePrefix

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

public bool QuotePrefix { get; set; }

Property Value

bool

RotationAngle

Represents text rotation angle.

public int RotationAngle { get; set; }

Property Value

int

Remarks

0: Not rotated.

255: Top to Bottom.

-90: Downward.

90: Upward.

You can set 255 or value ranged from -90 to 90.

ShrinkToFit

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

public bool ShrinkToFit { get; set; }

Property Value

bool

TextDirection

Represents text reading order.

public TextDirectionType TextDirection { get; set; }

Property Value

TextDirectionType

VerticalAlignment

Gets or sets the vertical alignment type of the text in a cell.

public TextAlignmentType VerticalAlignment { get; set; }

Property Value

TextAlignmentType

Methods

Copy(Style)

Copies data from another style object

public void Copy(Style style)

Parameters

style Style

Source Style object

Remarks

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.

Equals(object)

Determines whether two Style instances are equal.

public override bool Equals(object obj)

Parameters

obj object

The Style object to compare with the current Style object.

Returns

bool

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

GetHashCode()

Serves as a hash function for a Style object.

public override int GetHashCode()

Returns

int

A hash code for the current Object.

Remarks

This method is only for internal use.

GetTwoColorGradientSetting()

Get the two-color gradient setting.

public TwoColorGradient GetTwoColorGradientSetting()

Returns

TwoColorGradient

IsModified(StyleModifyFlag)

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.

public bool IsModified(StyleModifyFlag modifyFlag)

Parameters

modifyFlag StyleModifyFlag

Style modified flags

Returns

bool

true if the specified properties have been modified

SetBorder(BorderType, CellBorderType, Color)

Sets the borders of the style.

public bool SetBorder(BorderType borderType, CellBorderType borderStyle, Color borderColor)

Parameters

borderType BorderType

The border(s) to be set, can be combination of Aspose.Cells.BorderType.

borderStyle CellBorderType

The style of the border.

borderColor Color

The color of the border.

Returns

bool

Whether current border settings have been changed.

SetBorder(BorderType, CellBorderType, CellsColor)

Sets the borders of the style.

public bool SetBorder(BorderType borderType, CellBorderType borderStyle, CellsColor borderColor)

Parameters

borderType BorderType

The border(s) to be set, can be combination of Aspose.Cells.BorderType.

borderStyle CellBorderType

The style of the border.

borderColor CellsColor

The color of the border.

Returns

bool

Whether current border settings have been changed.

SetCustom(string, bool)

Sets the Custom number format string of a cell.

public void SetCustom(string custom, bool builtinPreference)

Parameters

custom string

Custom number format string, should be InvariantCulture pattern.

builtinPreference bool

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.

SetPatternColor(BackgroundType, Color, Color)

Sets the background color.

public void SetPatternColor(BackgroundType pattern, Color color1, Color color2)

Parameters

pattern BackgroundType

The pattern.

color1 Color

The foreground color.

color2 Color

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

SetTwoColorGradient(Color, Color, GradientStyleType, int)

Sets the specified fill to a two-color gradient.

public void SetTwoColorGradient(Color color1, Color color2, GradientStyleType gradientStyleType, int variant)

Parameters

color1 Color

One gradient color.

color2 Color

Two gradient color.

gradientStyleType GradientStyleType

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.

ToJson()

Convert Aspose.Cells.Style to JSON struct data.

public string ToJson()

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.

public void Update()