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.
Constructors
| Name | Description |
|---|---|
| Style | Initializes a new instance of the Style class. NOTE: This constructor is now obsolete. Instead, please use CellsFactory. |
Properties
| Name | Type | Description |
|---|---|---|
| BackgroundThemeColor | ThemeColor | Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned. |
| ForegroundThemeColor | ThemeColor | Gets and sets the foreground theme color. If the foreground color is not a theme color, NULL will be returned. |
| Name | String | Gets or sets the name of the style. |
| Pattern | int | Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant. |
| Borders | BorderCollection | Gets the BorderCollection of the style. |
| BackgroundColor | Color | Gets or sets a style’s background color. If you want to set a cell’s color, please use Style.ForegroundColor property. O |
| BackgroundArgbColor | int | Gets and sets the background color with a 32-bit ARGB value. |
| ForegroundColor | Color | Gets or sets a style’s foreground color. It means no color setting if Color.Empty is returned. |
| ForegroundArgbColor | int | Gets and sets the foreground color with a 32-bit ARGB value. |
| HasBorders | boolean | Checks whether there are borders have been set for the style. |
| ParentStyle | Style | Gets the parent style of this style. |
| IsNumberFormatApplied | boolean | Indicate whether the number formatting should be applied. Only for named style. |
| IsFontApplied | boolean | Indicate whether the font formatting should be applied. Only for named style. |
| IsAlignmentApplied | boolean | Indicate whether the alignment formatting should be applied. Only for named style. |
| IsBorderApplied | boolean | Indicate whether the border formatting should be applied. Only for named style. |
| IsFillApplied | boolean | Indicate whether the fill formatting should be applied. Only for named style. |
| IsProtectionApplied | boolean | Indicate whether the protection formatting should be applied. Only for named style. |
| IndentLevel | int | Represents the indent level for the cell or range. Can only be an integer from 0 to 250. If text horizontal alignment ty |
| Font | Font | Gets a Font object. |
| RotationAngle | int | Represents text rotation angle. 0: Not rotated. 255: Top to Bottom. -90: Downward. 90: Upward. You can set 255 or value |
| HorizontalAlignment | int | Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer |
| VerticalAlignment | int | Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer c |
| IsTextWrapped | boolean | Gets or sets a value indicating whether the text within a cell is wrapped. |
| Number | int | Gets or sets the display format of numbers and dates. The formatting patterns are different for different regions. For e |
| IsLocked | boolean | Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet |
| Custom | String | Represents the custom number format string of this style object. If the custom number format is not set(For example, the |
| CultureCustom | String | Gets and sets the culture-dependent pattern string for number format. If no number format has been set for this object, |
| InvariantCustom | String | Gets the culture-independent pattern string for number format. If no number format has been set for this object, null wi |
| IsFormulaHidden | boolean | Represents if the formula will be hidden when the worksheet is protected. |
| ShrinkToFit | boolean | Represents if text automatically shrinks to fit in the available column width. |
| TextDirection | int | Represents text reading order. The value of the property is TextDirectionType integer constant. |
| IsJustifyDistributed | boolean | Indicates if the cells justified or distributed alignment should be used on the last line of text. This is typical for E |
| QuotePrefix | boolean | Indicates whether the cell’s value starts with single quote mark. |
| IsGradient | boolean | Indicates whether the cell shading is a gradient pattern. |
| IsPercent | boolean | Indicates whether the number format is a percent format. |
| IsDateTime | boolean | Indicates whether the number format is a date format. |
| IsCheckBox | boolean | |
| LeftBorder | Border | |
| RightBorder | Border | |
| TopBorder | Border | |
| BottomBorder | Border |
Methods
| Name | Description |
|---|---|
| setTwoColorGradient | Sets the specified fill to a two-color gradient. |
| getTwoColorGradient | Get the two-color gradient setting. |
If this is not gradient fill,return null; | | getTwoColorGradientSetting | Get the two-color gradient setting. | | toJson | Convert Style to JSON struct data. | | setPatternColor | Sets the background color. | | copy | Copies data from another style object
This method does not copy the name of the style. If you want to copy the name, pl | | update | Apply the named style to the styles of the cells which use this named style. It works like clicking the “ok” button afte | | isModified | Checks whether the specified properties of the style have been modified. Used for style of ConditionalFormattings to che | | equals | Determines whether two Style instances are equal. | | hashCode | Serves as a hash function for a Style object.
This method is only for internal use. | | setBorder | Sets the borders of the style. | | setCustom | Sets the Custom number format string of a cell. |
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.
Style.BackgroundThemeColor property
Gets and sets the background theme color. If the background color is not a theme color, NULL will be returned.
Type: ThemeColor
Style.ForegroundThemeColor property
Gets and sets the foreground theme color. If the foreground color is not a theme color, NULL will be returned.
Type: ThemeColor
Style.Name property
Gets or sets the name of the style.
Type: String
Style.Pattern property
Gets or sets the cell background pattern type. The value of the property is BackgroundType integer constant.
Type: int
Style.Borders property
Gets the BorderCollection of the style.
Type: BorderCollection
Style.BackgroundColor property
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.
Type: Color
Style.BackgroundArgbColor property
Gets and sets the background color with a 32-bit ARGB value.
Type: int
Style.ForegroundColor property
Gets or sets a style’s foreground color. It means no color setting if Color.Empty is returned.
Type: Color
Style.ForegroundArgbColor property
Gets and sets the foreground color with a 32-bit ARGB value.
Type: int
Style.HasBorders property
Checks whether there are borders have been set for the style.
Type: boolean
Style.ParentStyle property
Gets the parent style of this style.
Type: Style
Style.IsNumberFormatApplied property
Indicate whether the number formatting should be applied. Only for named style.
Type: boolean
Style.IsFontApplied property
Indicate whether the font formatting should be applied. Only for named style.
Type: boolean
Style.IsAlignmentApplied property
Indicate whether the alignment formatting should be applied. Only for named style.
Type: boolean
Style.IsBorderApplied property
Indicate whether the border formatting should be applied. Only for named style.
Type: boolean
Style.IsFillApplied property
Indicate whether the fill formatting should be applied. Only for named style.
Type: boolean
Style.IsProtectionApplied property
Indicate whether the protection formatting should be applied. Only for named style.
Type: boolean
Style.IndentLevel property
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.
Type: int
Style.Font property
Gets a Font object.
Type: Font
Style.RotationAngle property
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.
Type: int
Style.HorizontalAlignment property
Gets or sets the horizontal alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
Type: int
Style.VerticalAlignment property
Gets or sets the vertical alignment type of the text in a cell. The value of the property is TextAlignmentType integer constant.
Type: int
Style.IsTextWrapped property
Gets or sets a value indicating whether the text within a cell is wrapped.
Type: boolean
Style.Number property
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: 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 7 Currency $#,##0.00_);($#,##0.00) 8 Currency $#,##0.00_);Red 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 39 Accounting #,##0.00_);(#,##0.00) 40 Accounting #,##0.00_);Red 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 @
Type: int
Style.IsLocked property
Gets or sets a value indicating whether a cell can be modified or not. Locking cells has no effect unless the worksheet is protected.
Type: boolean
Style.Custom property
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.
Type: String
Style.CultureCustom property
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.
Type: String
Style.InvariantCustom property
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.
Type: String
Style.IsFormulaHidden property
Represents if the formula will be hidden when the worksheet is protected.
Type: boolean
Style.ShrinkToFit property
Represents if text automatically shrinks to fit in the available column width.
Type: boolean
Style.TextDirection property
Represents text reading order. The value of the property is TextDirectionType integer constant.
Type: int
Style.IsJustifyDistributed property
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.
Type: boolean
Style.QuotePrefix property
Indicates whether the cell’s value starts with single quote mark.
Type: boolean
Style.IsGradient property
Indicates whether the cell shading is a gradient pattern.
Type: boolean
Style.IsPercent property
Indicates whether the number format is a percent format.
Type: boolean
Style.IsDateTime property
Indicates whether the number format is a date format.
Type: boolean
Style.IsCheckBox property
Type: boolean
Style.LeftBorder property
Type: Border
Style.RightBorder property
Type: Border
Style.TopBorder property
Type: Border
Style.BottomBorder property
Type: Border
setTwoColorGradient(color1, color2, gradientStyleType, variant)
Sets the specified fill to a two-color gradient.
| Parameter | Type | Description |
|---|---|---|
| color1 | Color | One gradient color. |
| color2 | Color | Two gradient color. |
| gradientStyleType | int | A GradientStyleType value. 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. |
getTwoColorGradient()
Get the two-color gradient setting.
If this is not gradient fill,return null;
Returns: Returns all setting about two-color gradient [0] : Color1 [1] : Color2 [2] : GradientStyleType [3] : Variant
getTwoColorGradientSetting()
Get the two-color gradient setting.
toJson()
Convert Style to JSON struct data.
setPatternColor(pattern, color1, color2)
Sets the background color.
| Parameter | Type | Description |
|---|---|---|
| pattern | int | 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(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 | Type | Description |
|---|---|---|
| style | Style | Source Style object |
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(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.
| Parameter | Type | Description |
|---|---|---|
| modifyFlag | int | A StyleModifyFlag value. Style modified flags |
Returns: true if the specified properties have been modified
equals(obj)
Determines whether two Style instances are equal.
| Parameter | Type | Description |
|---|---|---|
| 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()
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(borderType, borderStyle, borderColor) (1 of 2)
Sets the borders of the style.
| Parameter | Type | Description |
|---|---|---|
| borderType | int | A BorderType value. The border(s) to be set, can be combination of BorderType . |
| borderStyle | int | A CellBorderType value. The style of the border. |
| borderColor | Color | The color of the border. |
Returns: Whether current border settings have been changed.
setBorder(borderType, borderStyle, borderColor) (2 of 2)
Sets the borders of the style.
| Parameter | Type | Description |
|---|---|---|
| borderType | int | A BorderType value. The border(s) to be set, can be combination of BorderType . |
| borderStyle | int | A CellBorderType value. The style of the border. |
| borderColor | CellsColor | The color of the border. |
Returns: Whether current border settings have been changed.
setCustom(custom, builtinPreference)
Sets the Custom number format string of a cell.
| Parameter | Type | 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. |