Spread.Services Documentation
Add Color Scale Rule
Spread.Services Documentation > Developer's Guide > Apply Conditional Formatting > Add Color Scale Rule

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.

Refer to the following example code to add color scale rule to a cell range in a worksheet.

C#
Copy Code
// 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.FromRGB(255, 0, 0);

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