# Color Scale Rule

Format cells or a range of cells in DsExcel with the color scale rule that uses a sliding color scale.

## Content

The color scale rule uses a sliding color scale to format cells or a range of cells. For instance, if numeric cell value 1 is represented with color yellow and 50 with green, then 25 would be light green. This rule can be added using the properties and methods of the [IColorScale interface](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IColorScale.html).
Refer to the following example code to add color scale rule to a cell range in a worksheet.

```csharp
// Adding colorscale rule
IColorScale twoColorScaleRule = worksheet.Range["A2:E2"].FormatConditions.AddColorScale(ColorScaleType.TwoColorScale);

worksheet.Range["A2"].Value = 1;
worksheet.Range["B2"].Value = 2;
worksheet.Range["C2"].Value = 3;
worksheet.Range["D2"].Value = 4;
worksheet.Range["E2"].Value = 5;
            
twoColorScaleRule.ColorScaleCriteria[0].Type = ConditionValueTypes.Number;
twoColorScaleRule.ColorScaleCriteria[0].Value = 1;
twoColorScaleRule.ColorScaleCriteria[0].FormatColor.Color = Color.FromArgb(255, 0, 0);

twoColorScaleRule.ColorScaleCriteria[1].Type = ConditionValueTypes.Number;
twoColorScaleRule.ColorScaleCriteria[1].Value = 5;
twoColorScaleRule.ColorScaleCriteria[1].FormatColor.Color = Color.FromArgb(0, 255, 0);
```