# Understanding the Style Model

This topic explains about the Style model used in Spread for ASP.NET. Learn more in documentation.

## Content

The style model includes appearance settings, whether determined in the Spread Designer, or set as properties in the Properties List or as inherited by a custom skin for a whole sheet or by a custom style for individual cells. For more information on appearance settings for a sheet, refer to [Creating a Skin for Sheets](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-appearSet/spweb-appearSheet/spweb-SheetSkinCreate) and [Applying a Skin to a Sheet](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-appearSet/spweb-appearSheet/spweb-SheetSkinApply). For more information on appearance settings for a cell, refer to [Creating and Applying a Custom Style for Cells](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-appearSet/spweb-appearCell/spweb-cellstyle).

## Overview

The appearance settings may be set from any of the following classes in the Spread namespace that represent shortcut objects:

* [Cell](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Cell.html)
* [Column](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Column.html)
* [Row](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Row.html)
* [AlternatingRow](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.AlternatingRow.html)

They also may be set from any of these classes in the Spread namespace that affect style:

* [Appearance](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Appearance.html)
* [Border](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Border.html)
* [DefaultSkins](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.DefaultSkins.html)
* [NamedStyle](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.NamedStyle.html)
* [SheetSkin](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetSkin.html)

The order of inheritance is described in [Object Parentage](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-concepts/spweb-oviewconcepts/spweb-knowObjParentage). Here is a list of the style properties that are included in the style model, which are basically the members of the [StyleInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.StyleInfo.html) class, and affect the appearance or style of a cell:

* BackColor
* Border
* CellType
* Editor
* Font
* ForeColor
* Formatter
* HorizontalAlignment
* Locked
* Renderer
* VerticalAlignment

The style model includes the cell types as well. The various cell types determine the appearance of a cell in several ways. For more information about the various cell types, refer to [Customizing with Cell Types](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-setCellTypes).
To use the underlying style model, use the methods of the style model for that sheet, specifically the [GetDirectInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.ISheetStyleModel.GetDirectInfo.html) method and [SetDirectInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.ISheetStyleModel.SetDirectInfo.html) method, and the settings in the [StyleInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.StyleInfo.html) object. Refer to the [Assembly Reference](/spreadnet/docs/latest/online-asp/overview/assembly-reference) for more information on the style model in general and to the [DefaultSheetStyleModel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.DefaultSheetStyleModel.html) methods in particular.

## Direct Versus Composite

“Direct” in the style model means “not composite” or “not inherited.” [SetDirectInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.ISheetStyleModel.SetDirectInfo.html) sets the style properties that have been set for the specified cell, column, or row directly and does not return any settings that are set for higher levels (such as the entire model), while [GetCompositeInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.ISheetStyleModel.GetCompositeInfo.html) gives the style properties "composed" or "merged" into one [StyleInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.StyleInfo.html) object that contains all the settings that are used to paint and edit the cell, column, or row, including any inherited settings.

## Styles

Properties that correspond to [StyleInfo](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.StyleInfo.html) properties are stored in the style model through the [ISheetStyleModel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.ISheetStyleModel.html) interface. Style properties can be set for a cell, row (column index set to -1), column (row index set to -1), or the entire model (column and row index set to -1). Properties that are not set in a cell are inherited from the row setting, or the column setting if the row has no setting, or the model default if the column also has no setting. The default is exposed through the **DefaultStyle** property (SheetView.[DefaultStyle](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetView.DefaultStyle.html), ColumnHeader.[DefaultStyle](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.ColumnHeader.DefaultStyle.html), and RowHeader.[DefaultStyle](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.RowHeader.DefaultStyle.html)).
If you set or get a style property using Rows.Default or Rows[-1] or Columns.Default or Columns[-1], then you will actually be setting or getting the DefaultStyle property. This is because Column and Row always use a row index of -1 and a column index of -1 when accessing the style model, respectively, and so using a column index or a row index of -1 will be setting or getting the model default.
Setting **StyleName** replaces the style in the style model with the [NamedStyle](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.NamedStyle.html) having the specified name. This has the effect of changing the settings of all of the style-related properties, including **ParentStyleName** (which wraps StyleInfo.Parent). Any previous setting for style-related properties like **BackColor**, **Font**, **Border**, or **ParentStyleName** are overwritten when you set **StyleName**. The component expects that the named style is set up with all the properties as you want them to be set. If this includes the named style having a parent NamedStyle, then you should have that parent set already when you assign it with **StyleName**, or you should assign it separately using a reference to the **NamedStyle** object (this has the same effect as setting ParentStyleName after setting StyleName). Keep in mind that after you have set **StyleName**, all cells where you have used that name are sharing the same **NamedStyle** object, and any changes that you make to one of those cells will also be changing all of the other cells sharing the same named style.

## Example

The style properties for a cell can be composited or merged from the **Cell**, **Row**, **Column**, **Sheet**, and parent **NamedStyle** objects. This code snippet illustrates the order of inheritance of a composited style:

```csharp
NamedStyle test_parent = new NamedStyle("test_parent");
NamedStyle test = new NamedStyle("test", "test parent");
test_parent.BackColor = Color.Red;
test.ForeColor = Color.White;
FpSpread1.NamedStyles.AddRange(new NamedStyle[] {test_parent, test});
FpSpread1.Sheets(0).Columns(0).BackColor = Color.Blue;
FpSpread1.Sheets(0).Rows(0).CellType = new NumberCellType();
FpSpread1.Sheets(0).Cells(0,0).StyleName = "test";
FpSpread1.Sheets(0).Cells(1,0).StyleName = "test";
```

This code creates two **NamedStyle** objects with a parent-child relationship, then sets some properties on the styles and adds them to the **NamedStyleCollection** in the FpSpread component. Then the background color for the first column is set to blue and the cell type for the first row is set to Number, and the first cells in the first two rows are both set to use the NamedStyle named “test.” The result is that the cells in the first column are blue, except for the cells in the first two rows, which are red because the “test” style inherits the red background color from its parent NamedStyle. The parent style overrides the inherited setting for the column.
The cell type for the first cell is Number, since there is no cell type set in either **NamedStyle** object. There is a cell type set in the first row which is inherited by all cells in the row. The cell type for the second cell is General since there is no cell type setting for the cell, row, or column. The default cell type for the sheet is General. For more information on inheritance of style settings, refer to [Object Parentage](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-concepts/spweb-oviewconcepts/spweb-knowObjParentage).

## Formatting Information

The FormatInfo strings in a saved XML file are **DateTimeFormatInfo** or **NumberFormatInfo** objects that store the format of the data. These are created in the style model when a General cell is edited, if the style model implements IParseFormatSupport. These format objects allow the cells to display the data in the same format that was used to enter it. The General cell type parses the string into a number or DateTime, and generates the IFormatProvider and format string necessary to render the data as it was entered. If you use TextCellType instead of GeneralCellType, then it works the same as the edit cells did in the ActiveX Spread, and no FormatInfo is stored in the style model, but the data entered into the cells is always treated as text.