Back to Devexpress

TextConditionalFormatting Interface

officefileapi-devexpress-dot-spreadsheet-9fdfea8d.md

latest5.1 KB
Original Source

TextConditionalFormatting Interface

Represents a conditional formatting rule that formats cells that contain or do not contain the given text.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

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

The following members return TextConditionalFormatting objects:

Remarks

The conditional formatting rule specified by the TextConditionalFormatting object highlights cells based on the text they contain. 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.AddTextConditionalFormatting method) or remove (the ConditionalFormattingCollection.Remove method) the conditional format.

Example

This example demonstrates how to create a rule that applies a conditional format based on the text in a cell.

  1. To create a new conditional formatting rule represented by the TextConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddTextConditionalFormatting 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 TextConditionalFormatting object.

Note

Transparency is not supported in conditional formatting.

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

View Example

vb
' Create the rule to highlight values with the given text string in cells A2 through A15.
Dim cfRule As TextConditionalFormatting = worksheet.ConditionalFormattings.AddTextConditionalFormatting(worksheet.Range("$A$2:$A$15"), ConditionalFormattingTextCondition.Contains, "Bradbury")
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to pink.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HE1, &H95, &HC2)
csharp
// Create the rule to highlight values with the given text string in cells A2 through A15.
TextConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddTextConditionalFormatting(worksheet.Range["$A$2:$A$15"], ConditionalFormattingTextCondition.Contains, "Bradbury");
// Specify formatting options to be applied to cells if the condition is true.
// Set the background color to pink.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xE1, 0x95, 0xC2);

See Also

TextConditionalFormatting Members

DevExpress.Spreadsheet Namespace