Back to Devexpress

FormulaExpressionConditionalFormatting Interface

officefileapi-devexpress-dot-spreadsheet-23fcbbff.md

latest5.3 KB
Original Source

FormulaExpressionConditionalFormatting Interface

Represents a conditional formatting rule that uses a formula as a formatting criteria.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface FormulaExpressionConditionalFormatting :
    ConditionalFormatting,
    ISupportsFormatting
vb
Public Interface FormulaExpressionConditionalFormatting
    Inherits ConditionalFormatting,
             ISupportsFormatting

The following members return FormulaExpressionConditionalFormatting objects:

Remarks

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.

Example

This example demonstrates how to create the rule that uses a formula as a criterion to apply a conditional format.

  1. To create a new conditional formatting rule represented by the FormulaExpressionConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddFormulaExpressionConditionalFormatting method. Pass the following parameters:

  2. Specify formatting options to be applied to cells if the condition is true , using the ISupportsFormatting.Formatting property of the FormulaExpressionConditionalFormatting object.

Note

Transparency is not supported in conditional formatting.

To remove the FormulaExpressionConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

View Example

csharp
// 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);
vb
' Create the rule to shade alternate rows without applying a new style.
Dim cfRule As FormulaExpressionConditionalFormatting = 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, &HBC, &HDA, &HF7)

See Also

FormulaExpressionConditionalFormatting Members

DevExpress.Spreadsheet Namespace