Represents a conditional formatting rule that uses a relational operator to determine which cells to format.
The conditional formatting rule specified by the ExpressionConditionalFormatting object highlights cells whose values meet the condition expressed by the relational operator. 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.AddExpressionConditionalFormatting method) or remove (the ConditionalFormattingCollection.Remove method) the conditional format.
This example demonstrates how to create the rule that uses a relational operator as a formatting criteria.
To create a new conditional formatting rule represented by the ExpressionConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddExpressionConditionalFormatting method. Pass the following parameters:
- Specify formatting options to be applied to cells if the condition is true, using the ISupportsFormatting.Formatting property of the ExpressionConditionalFormatting object. Set the background and font colors.
Transparency is not supported in conditional formatting.
// Create the rule to identify values that are above the average in cells F2 through F15. ExpressionConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddExpressionConditionalFormatting(worksheet.Range["$F$2:$F$15"], ConditionalFormattingExpressionCondition.GreaterThan, "=AVERAGE($F$2:$F$15)"); // Specify formatting options to be applied to cells if the condition is true. // Set the background color to yellow. cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA); // Set the font color to red. cfRule.Formatting.Font.Color = Color.Red;
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ExpressionConditionalFormatting 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.