Class CellStyleTemplate
A reusable bundle of cell formatting (font, fill, borders, alignment, number format) that can be stamped onto many cells efficiently. Equivalent to Excel's "Home > Cell Styles" and "Format Painter" functionality.
Inherited Members
Namespace: DRIT.Spreadsheet
Assembly: DRIT.Spreadsheet.dll
Syntax
public class CellStyleTemplate
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
Examples
var template = new CellStyleTemplate
{
FontBold = true,
FontSize = 14,
FontColor = SpreadsheetColor.FromRgb(255, 0, 0),
FillBackgroundColor = SpreadsheetColor.FromRgb(255, 255, 0),
BorderStyle = BorderStyle.Thin,
BorderColor = SpreadsheetColor.FromRgb(0, 0, 0),
FormatCode = "#,##0.00"
};
foreach (var cell in range.Cells)
cell.ApplyStyle(template);
Constructors
CellStyleTemplate()
A reusable bundle of cell formatting (font, fill, borders, alignment, number format) that can be stamped onto many cells efficiently. Equivalent to Excel's "Home > Cell Styles" and "Format Painter" functionality.
Declaration
public CellStyleTemplate()
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
Examples
var template = new CellStyleTemplate
{
FontBold = true,
FontSize = 14,
FontColor = SpreadsheetColor.FromRgb(255, 0, 0),
FillBackgroundColor = SpreadsheetColor.FromRgb(255, 255, 0),
BorderStyle = BorderStyle.Thin,
BorderColor = SpreadsheetColor.FromRgb(0, 0, 0),
FormatCode = "#,##0.00"
};
foreach (var cell in range.Cells)
cell.ApplyStyle(template);
Properties
BorderColor
Specifies the border color for all four edges.
Declaration
public SpreadsheetColor BorderColor { get; set; }
Property Value
| Type | Description |
|---|---|
| SpreadsheetColor |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
BorderStyle
Specifies the border style for all four edges.
Declaration
public BorderStyle? BorderStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| BorderStyle? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FillBackgroundColor
Specifies the fill background (pattern) color.
Declaration
public SpreadsheetColor FillBackgroundColor { get; set; }
Property Value
| Type | Description |
|---|---|
| SpreadsheetColor |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FillForegroundColor
Specifies the fill foreground color.
Declaration
public SpreadsheetColor FillForegroundColor { get; set; }
Property Value
| Type | Description |
|---|---|
| SpreadsheetColor |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FillPatternType
Specifies the fill pattern type.
Declaration
public PatternType? FillPatternType { get; set; }
Property Value
| Type | Description |
|---|---|
| PatternType? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontBold
Gets or sets whether the font is bold.
Declaration
public bool? FontBold { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontColor
Specifies the font color.
Declaration
public SpreadsheetColor FontColor { get; set; }
Property Value
| Type | Description |
|---|---|
| SpreadsheetColor |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontItalic
Gets or sets whether the font is italic.
Declaration
public bool? FontItalic { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontName
Specifies the font name.
Declaration
public string FontName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontSize
Specifies the font size in points.
Declaration
public double? FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| double? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FontUnderline
Specifies the underline type for the font.
Declaration
public SpreadsheetUnderline? FontUnderline { get; set; }
Property Value
| Type | Description |
|---|---|
| SpreadsheetUnderline? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
Format
Specifies a pre-parsed Format instance. When set, this takes precedence over FormatCode.
Declaration
public Format Format { get; set; }
Property Value
| Type | Description |
|---|---|
| Format |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
FormatCode
Specifies the number format code.
Declaration
public string FormatCode { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
HorizontalAlignment
Specifies the horizontal alignment.
Declaration
public HorizontalCellAlignment? HorizontalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| HorizontalCellAlignment? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
VerticalAlignment
Specifies the vertical alignment.
Declaration
public VerticalCellAlignment? VerticalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| VerticalCellAlignment? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.
WrapText
Gets or sets whether text wrapping is enabled.
Declaration
public bool? WrapText { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Remarks
Create a template once, configure its properties, then call ApplyStyle(CellStyleTemplate) on each cell. This avoids repeating individual formatting calls in tight loops.