# 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 methods of the [IColorScale](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IColorScale.html) interface.

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

```Java
// Adding Color Scale Rule 
IColorScale twoColorScaleRule = worksheet.getRange("A2:E2").getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);

worksheet.getRange("A2").setValue(1);
worksheet.getRange("B2").setValue(2);
worksheet.getRange("C2").setValue(3);
worksheet.getRange("D2").setValue(4);
worksheet.getRange("E2").setValue(5);

twoColorScaleRule.getColorScaleCriteria().get(0).setType(ConditionValueTypes.Number);
twoColorScaleRule.getColorScaleCriteria().get(0).setValue(1);
twoColorScaleRule.getColorScaleCriteria().get(0).getFormatColor().setColor(Color.FromArgb(255,0,0));

twoColorScaleRule.getColorScaleCriteria().get(1).setType(ConditionValueTypes.Number); 
twoColorScaleRule.getColorScaleCriteria().get(1).setValue(5);
twoColorScaleRule.getColorScaleCriteria().get(1).getFormatColor().setColor(Color.FromArgb(0,255,0));
```