You can use the StyleInfo object to create a style. The style can contain settings such as borders, colors, fonts, font and color themes, padding, cell indent, and alignment.
Styles can be assigned to cells, columns, rows, sheets, and conditional formats.
You can use the StyleName property to set the style for a cell, column, or row. Use the DefaultStyle property for the sheet. You can also use the Parent property to set a style for a range of cells that may individually have different style name values set. A cell inherits all the style information from the parent style. So different cells (cells in different rows or columns) may have different named styles but have the same parent style. For example, the cells may have different text colors (set in the named style) but inherit the same background color (set in the parent style).
The cell setting will override the row which overrides the column which overrides the sheet.
The following example sets colors and borders for cells and a row.
CS |
Copy Code
|
---|---|
gcSpreadSheet1.Sheets[0].NamedStyles.Add(new GrapeCity.Windows.SpreadSheet.Data.StyleInfo() { Background = new SolidColorBrush(Colors.Red), Name = "aaa", VerticalAlignment = GrapeCity.Windows.SpreadSheet.Data.CellVerticalAlignment.Center } ); private void button1_Click(object sender, RoutedEventArgs e) |
VB.NET |
Copy Code
|
---|---|
GcSpreadSheet1.Sheets(0).NamedStyles.Add(New GrapeCity.Windows.SpreadSheet.Data.StyleInfo() With {.Background = New SolidColorBrush(Colors.Red), .Name = "aaa", .VerticalAlignment = GrapeCity.Windows.SpreadSheet.Data.CellVerticalAlignment.Center}) Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click |