Click or drag to resize

CellStyle Constructor (ExcelFile)

Initializes a new instance of the CellStyle class which references default (Normal) style from the specified workbook.

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public CellStyle(
	ExcelFile workbook


Type: GemBox.SpreadsheetExcelFile
The workbook from which default (Normal) style this CellStyle inherits formatting.

Preferable way to modify formatting property of multiple cells is to get CellRange to which all those cells belong, and use Style property of that range to make the modification.

If modifying multiple formatting properties of a CellRange, without preserving unmodified formatting properties, preferable way is to create new instance of CellStyle, make modifications on it, and assign it to Style property of that range.


Following code demonstrates when not to and when to initialize a new instance of the CellStyle class:

// To modify a single formatting property on a range of cells, simply modify it.
// Other formatting properties will remain unchanged.
sheet.Cells.Style.Font.Italic = true;

// To modify multiple formatting properties on a range of cells, create new CellStyle instance, modify it, and assign it to a range of cells.
// All formatting properties are changed.
sheet.Cells.Style = new CellStyle(sheet.Parent)
    NumberFormat = "#,##0.00",
    HorizontalAlignment = HorizontalAlignmentStyle.Center,
    Locked = false
See Also