Represents a conditional formatting rule that uses a formula as a formatting criteria.
The conditional formatting rule specified by the FormulaExpressionConditionalFormatting object contains a formula to be evaluated. When the formula result is true, the cell is highlighted. The Worksheet.ConditionalFormattings property returns the ConditionalFormattingCollection collection that stores all conditional formatting rules specified on a worksheet. Use the methods of the ConditionalFormattingCollection object to apply (the ConditionalFormattingCollection.AddFormulaExpressionConditionalFormatting method) or remove (the ConditionalFormattingCollection.Remove method) the conditional format.
This example demonstrates how to create the rule that uses a formula as a criterion to apply a conditional format.
To create a new conditional formatting rule represented by the
FormulaExpressionConditionalFormattingobject, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddFormulaExpressionConditionalFormatting method. Pass the following parameters:
- A CellRange object that defines a range of cells to which the rule is applied.
- A string value that determines a formula to evaluate.
- Specify formatting options to be applied to cells if the condition is true, using the ISupportsFormatting.Formatting property of the
Transparency is not supported in conditional formatting.
// Create the rule to shade alternate rows without applying a new style. FormulaExpressionConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddFormulaExpressionConditionalFormatting(worksheet.Range["$A$2:$G$15"], "=MOD(ROW(),2)=1"); // Specify formatting options to be applied to cells if the condition is true. // Set the background color to light blue. cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xBC, 0xDA, 0xF7);
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the FormulaExpressionConditionalFormatting interface.
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.