[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Expand]Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [Expand]Formatting Cells
   [Collapse]Conditional Formatting
     How to: Format Cell Values that are Above or Below the Average
     How to: Format Cells that are Between or Not Between Two Values
     How to: Format Top or Bottom Ranked Values
     How to: Format Cells based on the Text in the Cell
     How to: Format Unique or Duplicate Values, Blank Cells and Formula Errors
     How to: Format Cells that Contain Dates
     How to: Format Cells that are Less than, Greater than or Equal to a Value
     How to: Use a Formula to Determine which Cells to Format
     How to: Format Cells Using a Two-Color Scale
     How to: Format Cells Using a Three-Color Scale
     How to: Format Cells Using Data Bars
     How to: Format Cells Using Icon Sets
   [Expand]Group Data
   [Expand]Filter Data
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Format Cells Using a Two-Color Scale

This example demonstrates how to apply a two-color scale conditional formatting rule.

  1. First of all, specify the minimum and maximum thresholds of a range using the ConditionalFormattingCollection.CreateValue method that creates an instance of the ConditionalFormattingValue object. This object provides access to threshold values and their types. The type of the threshold value is determined by one of the ConditionalFormattingValueType enumeration values and can be a number, percent, formula, or percentile. Call the ConditionalFormattingCollection.CreateValue method with the ConditionalFormattingValueType.MinMax parameter to set the minimum and maximum thresholds to the lowest and highest values in a range of cells, respectively.
  2. To apply a conditional formatting rule represented by the ColorScale2ConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddColorScale2ConditionalFormatting method with the following parameters:

    • A Range object that defines a range of cells to which the rule is applied.
    • A minimum threshold specified by the ConditionalFormattingValue object.
    • A color corresponding to the minimum value in a range of cells.
    • A maximum threshold specified by the ConditionalFormattingValue object.
    • A color corresponding to the maximum value in a range of cells.

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

The image below shows the result (the workbook is opened in Microsoft® Excel®). Cost distribution is shown using a gradation of two colors. Blue represents the lower values and yellow represents the higher values.

Is this topic helpful?​​​​​​​