Back to Devexpress

RankConditionalFormatting Interface

officefileapi-devexpress-dot-spreadsheet-4deaa695.md

latest5.4 KB
Original Source

RankConditionalFormatting Interface

Represents a "top/bottom N" conditional formatting rule.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

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

The following members return RankConditionalFormatting objects:

Remarks

The conditional formatting rule specified by the RankConditionalFormatting object formats cell values that fall in the top/bottom N bracket. 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.AddRankConditionalFormatting method) or remove (the ConditionalFormattingCollection.Remove method) the conditional format.

Example

This example demonstrates how to apply a "top/bottom N" conditional formatting rule.

  1. To create a new conditional formatting rule represented by the RankConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddRankConditionalFormatting 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 RankConditionalFormatting object. Define the background and font colors, and set the outline borders.

Note

Transparency is not supported in conditional formatting.

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

View Example

csharp
// Create the rule to identify top three values in cells F2 through F15.
RankConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRankConditionalFormatting(worksheet.Range["$F$2:$F$15"], ConditionalFormattingRankCondition.TopByRank, 3);
// Specify formatting options to be applied to cells if the condition is true.
// Set the background color to dark orchid.
cfRule.Formatting.Fill.BackgroundColor = Color.DarkOrchid;
// Set the outline borders.
cfRule.Formatting.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
// Set the font color to white.
cfRule.Formatting.Font.Color = Color.White;
vb
' Create the rule to identify top three values in cells F2 through F15.
Dim cfRule As RankConditionalFormatting = worksheet.ConditionalFormattings.AddRankConditionalFormatting(worksheet.Range("$F$2:$F$15"), ConditionalFormattingRankCondition.TopByRank, 3)
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to dark orchid.
cfRule.Formatting.Fill.BackgroundColor = Color.DarkOrchid
' Set the outline borders.
cfRule.Formatting.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin)
' Set the font color to white.
cfRule.Formatting.Font.Color = Color.White

See Also

RankConditionalFormatting Members

DevExpress.Spreadsheet Namespace