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
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
BackgroundColor
Gets or sets a style’s background color.
public Color BackgroundColor { get; set; }
Property Value
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
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
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
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
Remarks
The returned custom string is culture-independent.
Font
Gets a Aspose.Cells.Style.Font object.
public Font Font { get; }
Property Value
ForegroundArgbColor
Gets and sets the foreground color with a 32-bit ARGB value.
public int ForegroundArgbColor { get; set; }
Property Value
ForegroundColor
Gets or sets a style’s foreground color.
public Color ForegroundColor { get; set; }
Property Value
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
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
HorizontalAlignment
Gets or sets the horizontal alignment type of the text in a cell.
public TextAlignmentType HorizontalAlignment { get; set; }
Property Value
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
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
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
Remarks
Only for named style.
IsBorderApplied
Indicate whether the border formatting should be applied.
public bool IsBorderApplied { get; set; }
Property Value
Remarks
Only for named style.
IsDateTime
Indicates whether the number format is a date format.
public bool IsDateTime { get; }
Property Value
IsFillApplied
Indicate whether the fill formatting should be applied.
public bool IsFillApplied { get; set; }
Property Value
Remarks
Only for named style.
IsFontApplied
Indicate whether the font formatting should be applied.
public bool IsFontApplied { get; set; }
Property Value
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
IsGradient
Indicates whether the cell shading is a gradient pattern.
public bool IsGradient { get; set; }
Property Value
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
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
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
Remarks
Only for named style.
IsPercent
Indicates whether the number format is a percent format.
public bool IsPercent { get; }
Property Value
IsProtectionApplied
Indicate whether the protection formatting should be applied.
public bool IsProtectionApplied { get; set; }
Property Value
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
Name
Gets or sets the name of the style.
public string Name { get; set; }
Property Value
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
Remarks
For example, the formatting patterns represented by numbers for en_US region:
Value | Type | Format String |
---|---|---|
0 | General | General |
1 | Decimal | 0 |
2 | Decimal | 0.00 |
3 | Decimal | #,##0 |
4 | Decimal | #,##0.00 |
5 | Currency | $#,##0_);($#,##0) |
6 | Currency | $#,##0_);[Red]($#,##0) |
7 | Currency | $#,##0.00_);($#,##0.00) |
8 | Currency | $#,##0.00_);[Red]($#,##0.00) |
9 | Percentage | 0% |
10 | Percentage | 0.00% |
11 | Scientific | 0.00E+00 |
12 | Fraction | # ?/? |
13 | Fraction | # ??/?? |
14 | Date | m/d/yyyy |
15 | Date | d-mmm-yy |
16 | Date | d-mmm |
17 | Date | mmm-yy |
18 | Time | h:mm AM/PM |
19 | Time | h:mm:ss AM/PM |
20 | Time | h:mm |
21 | Time | h:mm:ss |
22 | Time | m/d/yyyy h:mm |
37 | Accounting | #,##0_);(#,##0) |
38 | Accounting | #,##0_);[Red](#,##0) |
39 | Accounting | #,##0.00_);(#,##0.00) |
40 | Accounting | #,##0.00_);[Red](#,##0.00) |
41 | Accounting | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
42 | Currency | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) |
43 | Accounting | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
44 | Currency | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) |
45 | Time | mm:ss |
46 | Time | [h]:mm:ss |
47 | Time | mm:ss.0 |
48 | Scientific | ##0.0E+0 |
49 | Text | @ |
ParentStyle
Gets the parent style of this style.
public Style ParentStyle { get; }
Property Value
Pattern
Gets or sets the cell background pattern type.
public BackgroundType Pattern { get; set; }
Property Value
QuotePrefix
Indicates whether the cell’s value starts with single quote mark.
public bool QuotePrefix { get; set; }
Property Value
RotationAngle
Represents text rotation angle.
public int RotationAngle { get; set; }
Property Value
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
TextDirection
Represents text reading order.
public TextDirectionType TextDirection { get; set; }
Property Value
VerticalAlignment
Gets or sets the vertical alignment type of the text in a cell.
public TextAlignmentType VerticalAlignment { get; set; }
Property Value
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
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
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
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
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
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
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
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()