Spread WPF 17
Spread WPF Documentation / Developer's Guide / Customizing the Appearance / Using Conditional Formatting
In This Topic
    Using Conditional Formatting
    In This Topic

    GcSpreadSheet supports conditional formatting in cells. You can use styles to set the visual appearance of the formatted cell. There are several types of conditional rules. They are as follows:

    The average rule checks for values above or under the average. The cell value rule compares values. The date rule compares dates. The formula rule allows you to use formulas when checking the condition.

    The specific text rule searches for text strings. The top 10 rule checks for values in the top or bottom of the range.

    The unique rule checks to see if the value is the only one of that value in the range (if the duplicate option is false). The duplicate rule checks for duplicate values.

    The data bar rule displays a bar in the cell based on the cell value in the range. You can also specify the type and color of the bar or borders. You can specify the axis position and color as well. The following image displays a data bar rule.

    Data Bar Rule Example

    The icon set rule displays icons based on the values. You can specify the type of icon and whether to show the icon or the icon and the data in the cell. The following image displays an icon rule.

    Icon Rule Example

    The scale rule uses a sliding color scale. For example if 1 is yellow and 50 is green, then 25 would be light green. The scale rule has an option for two or three colors in the scale (TwoColorScaleRule Class or ThreeColorScaleRule Class). The following image is for a three scale rule.

    Three Scale Rule Example

    The StyleInfo class can be used to set styles for rules that do not have color or icon properties.

    Using Code

    The following example creates a three color scale rule and applies it to a range of cells.

    CS
    Copy Code
    var rule = GrapeCity.Windows.SpreadSheet.Data.ThreeColorScaleRule.Create(GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 1, Colors.Yellow, GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 50, Colors.Blue, GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 100, Colors.Red);
    rule.Ranges = new GrapeCity.Windows.SpreadSheet.Data.CellRange[] { new GrapeCity.Windows.SpreadSheet.Data.CellRange(0, 0, 20, 1) };
    gcSpreadSheet1.Sheets[0].ConditionalFormats.AddRule(rule);
    VB.NET
    Copy Code
    Dim rule = GrapeCity.Windows.SpreadSheet.Data.ThreeColorScaleRule.Create(GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 1, Colors.Yellow, GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 50, Colors.Blue, _
     GrapeCity.Windows.SpreadSheet.Data.ScaleValueType.Number, 100, Colors.Red)
    rule.Ranges = New GrapeCity.Windows.SpreadSheet.Data.CellRange() {New GrapeCity.Windows.SpreadSheet.Data.CellRange(0, 0, 20, 1)}
    GcSpreadSheet1.Sheets(0).ConditionalFormats.AddRule(rule)
    See Also