officefileapi-devexpress-dot-spreadsheet-dot-conditionalformattingcollection-dot-addspecialconditionalformatting-x28-cellrange-conditionalformattingspecialcondition-x29.md
Applies the conditional formatting rule that formats cells which contain the specified values (unique or duplicate values, formula errors, etc.).
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
SpecialConditionalFormatting AddSpecialConditionalFormatting(
CellRange range,
ConditionalFormattingSpecialCondition condition
)
Function AddSpecialConditionalFormatting(
range As CellRange,
condition As ConditionalFormattingSpecialCondition
) As SpecialConditionalFormatting
| Name | Type | Description |
|---|---|---|
| range | CellRange |
A CellRange object that specifies a range of cells to which the conditional formatting rule is applied.
| | condition | ConditionalFormattingSpecialCondition |
One of the ConditionalFormattingSpecialCondition enumeration values.
|
| Type | Description |
|---|---|
| SpecialConditionalFormatting |
A SpecialConditionalFormatting object that represents the specified conditional format.
|
This example demonstrates how to specify the rule that highlights unique or duplicate values, formula errors, etc.
To create a new conditional formatting rule represented by the SpecialConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddSpecialConditionalFormatting 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 SpecialConditionalFormatting object.
Note
Transparency is not supported in conditional formatting.
To remove the SpecialConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.
// Create the rule to identify unique values in cells A2 through A15.
SpecialConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range["$A$2:$A$15"], ConditionalFormattingSpecialCondition.ContainUniqueValue);
// 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);
' Create the rule to identify unique values in cells A2 through A15.
Dim cfRule As SpecialConditionalFormatting = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range("$A$2:$A$15"), ConditionalFormattingSpecialCondition.ContainUniqueValue)
' 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, &HFA, &HF7, &HAA)
The following code snippets (auto-collected from DevExpress Examples) contain references to the AddSpecialConditionalFormatting(CellRange, ConditionalFormattingSpecialCondition) method.
Note
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.
// Create the rule to identify unique values in cells A2 through A15.
SpecialConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet["$A$2:$A$15"], ConditionalFormattingSpecialCondition.ContainUniqueValue);
// Specify formatting options to be applied to cells if the condition is true.
// Create the rule to identify unique values in cells A2 through A15.
SpecialConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range["$A$2:$A$15"], ConditionalFormattingSpecialCondition.ContainUniqueValue);
// Specify formatting options to be applied to cells if the condition is true.
// Create the rule to identify unique values in cells A2 through A15.
SpecialConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range["$A$2:$A$15"], ConditionalFormattingSpecialCondition.ContainUniqueValue);
// Specify formatting options to be applied to cells if the condition is true.
' Create the rule to identify unique values in cells A2 through A15.
Dim cfRule As SpecialConditionalFormatting = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet("$A$2:$A$15"), ConditionalFormattingSpecialCondition.ContainUniqueValue)
' Specify formatting options to be applied to cells if the condition is true.
' Create the rule to identify unique values in cells A2 through A15.
Dim cfRule As SpecialConditionalFormatting = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range("$A$2:$A$15"), ConditionalFormattingSpecialCondition.ContainUniqueValue)
' Specify formatting options to be applied to cells if the condition is true.
' Create the rule to identify unique values in cells A2 through A15.
Dim cfRule As SpecialConditionalFormatting = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range("$A$2:$A$15"), ConditionalFormattingSpecialCondition.ContainUniqueValue)
' Specify formatting options to be applied to cells if the condition is true.
See Also
ConditionalFormattingCollection Interface