Method SetStyle
SetStyle(int, int, XlsxCellStyle)
Sets how a cell looks. Its value and its formula are kept.
public void SetStyle(int row, int column, XlsxCellStyle style)
Parameters
rowintThe one-based row.
columnintThe one-based column.
styleXlsxCellStyleThe look. To change one thing, start from the cell's own:
sheet.GetCell(r, c).Style.With(bold: true).
Remarks
The cell need not exist: an empty cell can be given a fill or a border. A look the workbook already has a cell format for uses that format; a new one is added to the workbook's formats without moving any that are there.
Only what XlsxCellStyle says is written, so the cell loses what the type has no member for: a theme colour becomes the RGB it resolved to, and a pattern fill, cell protection or a named cell style do not carry over.
In a file, a cell that states no vertical alignment sits at the bottom, and a cell read from a file says Bottom. Default says Top, and here that is written as top.
Exceptions
- ArgumentNullException
styleis null.- ArgumentOutOfRangeException
The row or the column is outside the worksheet grid.
- InvalidOperationException
The sheet is not a worksheet.
- InvalidDocumentException
The sheet's part is malformed.
SetStyle(string, XlsxCellStyle)
Sets how a cell looks by its reference. See SetStyle(int, int, XlsxCellStyle).
public void SetStyle(string reference, XlsxCellStyle style)
Parameters
referencestringThe reference, such as
B4.styleXlsxCellStyleThe look.
Exceptions
- ArgumentNullException
referenceorstyleis null.- ArgumentException
referenceis not a cell reference inside the worksheet grid.- InvalidOperationException
The sheet is not a worksheet.
- InvalidDocumentException
The sheet's part is malformed.