Table of Contents

Method SetStyle

Namespace
DocWright.Formats.Xlsx
Assembly
DocWright.Formats.Xlsx.dll

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

row int

The one-based row.

column int

The one-based column.

style XlsxCellStyle

The 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

style is 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

reference string

The reference, such as B4.

style XlsxCellStyle

The look.

Exceptions

ArgumentNullException

reference or style is null.

ArgumentException

reference is not a cell reference inside the worksheet grid.

InvalidOperationException

The sheet is not a worksheet.

InvalidDocumentException

The sheet's part is malformed.