You can configure the conditional formatting of a particular Worksheet
by using the many "Add" methods exposed on the ConditionalFormats collection of that worksheet. The first parameter of these "Add" methods is the string
region of the Worksheet that you would like to apply the conditional format to.
Many of the conditional formats that you can add to your Worksheet have a CellFormat
property that determines the way that the WorksheetCell elements should look when the condition in that conditional format holds true. For example, you can use the properties attached to this CellFormat property such as Fill and Font to determine the background and font settings of your cells, respectively.
When a conditional format is created and a CellFormat applied, there is a subset of properties that are currently supported by the Worksheet Cell
. The properties that are currently honored off of the CellFormat are Fill, Border properties, FormatString, and some Font properties such as Strikethrough, Underline, Italic, Bold, and Color. Many of these can be seen from the code snippet below.
There are a few conditional formats that do not have a CellFormat
property, as their visualization on the WorksheetCell
behaves differently. These conditional formats are the DataBarConditionalFormat
, ColorScaleConditionalFormat
, and IconSetConditionalFormat
.
When loading a pre-existing Workbook from Excel, the formats will be preserved when that Workbook is loaded. The same is true for when you save the Workbook out to an Excel file.