Style

Style class

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

Constructors

Name Description
Style() (Obsolete.) Initializes a new instance of the Style class.

Properties

Name Description
BackgroundArgbColor { get; set; } Gets and sets the background color with a 32-bit ARGB value.
BackgroundColor { get; set; } Gets or sets a style’s background color.
BackgroundThemeColor { get; set; } Gets and sets the background theme color.
Borders { get; } Gets the BorderCollection of the style.
CultureCustom { get; set; } 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.
Custom { get; set; } 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.
Font { get; } Gets a Font object.
ForegroundArgbColor { get; set; } Gets and sets the foreground color with a 32-bit ARGB value.
ForegroundColor { get; set; } Gets or sets a style’s foreground color.
ForegroundThemeColor { get; set; } Gets and sets the foreground theme color.
HasBorders { get; } Checks whether there are borders have been set for the style.
HorizontalAlignment { get; set; } Gets or sets the horizontal alignment type of the text in a cell.
IndentLevel { get; set; } Represents the indent level for the cell or range. Can only be an integer from 0 to 250.
InvariantCustom { get; } 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.
IsDateTime { get; } Indicates whether the number format is a date format.
IsFormulaHidden { get; set; } Represents if the formula will be hidden when the worksheet is protected.
IsGradient { get; set; } Indicates whether the cell shading is a gradient pattern.
IsJustifyDistributed { get; set; } Indicates if the cells justified or distributed alignment should be used on the last line of text.
IsLocked { get; set; } Gets or sets a value indicating whether a cell can be modified or not.
IsPercent { get; } Indicates whether the number format is a percent format.
IsTextWrapped { get; set; } Gets or sets a value indicating whether the text within a cell is wrapped.
Name { get; set; } Gets or sets the name of the style.
Number { get; set; } Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions.
ParentStyle { get; } Gets the parent style of this style.
Pattern { get; set; } Gets or sets the cell background pattern type.
QuotePrefix { get; set; } Indicates whether the cell’s value starts with single quote mark.
RotationAngle { get; set; } Represents text rotation angle.
ShrinkToFit { get; set; } Represents if text automatically shrinks to fit in the available column width.
TextDirection { get; set; } Represents text reading order.
VerticalAlignment { get; set; } Gets or sets the vertical alignment type of the text in a cell.

Methods

Name Description
Copy(Style) Copies data from another style object
override Equals(object) Determines whether two Style instances are equal.
override GetHashCode() Serves as a hash function for a Style object.
GetTwoColorGradient(out Color, out Color, out GradientStyleType, out int) Get the two-color gradient setting.
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.
SetBorder(BorderType, CellBorderType, Color) Sets the borders of the style.
SetCustom(string, bool) Sets the Custom number format string of a cell.
SetPatternColor(BackgroundType, Color, Color) Sets the background color.
SetTwoColorGradient(Color, Color, GradientStyleType, int) Sets the specified fill to a two-color gradient.
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.

Examples

[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);

See Also