Other API Samples

Live SpreadsheetGear API Samples

Snippets Conditional Format (Color Scale)

A sample that applies a color scale conditional format to a range.

IWorkbook workbook = Factory.GetWorkbook();
IWorksheet worksheet = workbook.ActiveWorksheet;
IRange range = worksheet.Cells["A1:F10"];
range.Formula = "=RAND()";
IFormatConditions conditions = range.FormatConditions;
IFormatCondition condition = conditions.AddColorScale(2);
IColorScale colorScale = condition.ColorScale;
colorScale.ColorScaleCriteria[0].Type = ConditionValueTypes.Number;
colorScale.ColorScaleCriteria[0].Value = 0;
colorScale.ColorScaleCriteria[1].Type = ConditionValueTypes.Number;
colorScale.ColorScaleCriteria[1].Value = 1;
Run This Sample
Render Image

Generate an image representation of the results of this sample, which uses the SpreadsheetGear.Drawing.Image class to convert ranges, charts and shapes to images.


Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.