Interface IColorScale
Represents a color scale conditional formatting rule.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.UWP.dll
Syntax
public interface IColorScale
Properties
Criteria
Gets a collection of individual IColorConditionValue objects. Read-only.
Declaration
IList<IColorConditionValue> Criteria { get; }
Property Value
Type |
---|
System.Collections.Generic.IList<IColorConditionValue> |
Remarks
The default size of the criteria list is 2 and it can be changed using SetConditionCount(Int32) method. To know more about Conditional formatting Types refer this link.
Examples
The criteria for applying color scale can be accessed from the Criteria Property. The following code illustrates how to access the IColorConditionValue objects from the criteria list and change the properties FormatColorRGB, Type and Value by accessing each criterio from the Criteria list.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Load data to Apply Conditional Formatting.
worksheet["A1"].Text = "ColorScale";
worksheet["A2"].Number = 10;
worksheet["A3"].Number = 20;
worksheet["A4"].Number = 30;
worksheet["A5"].Number = 40;
worksheet["A6"].Number = 50;
worksheet["A7"].Number = 60;
worksheet["A8"].Number = 70;
worksheet["A9"].Number = 80;
worksheet["A10"].Number = 90;
worksheet["A11"].Number = 100;
//Create instance of IConditonalFormat and IConditionalFormats.
IConditionalFormats formats = worksheet["A2:A11"].ConditionalFormats;
IConditionalFormat format = formats.AddCondition();
//Set FormatType as ColorScale.
format.FormatType = ExcelCFType.ColorScale;
IColorScale colorScale = format.ColorScale;
//Set 3 as count for color scale
colorScale.SetConditionCount(3);
//Set Criteria for applying ColorScale
colorScale.Criteria[0].FormatColorRGB = System.Drawing.Color.White;
colorScale.Criteria[0].Type = ConditionValueType.Percentile;
colorScale.Criteria[0].Value = "0";
colorScale.Criteria[1].FormatColorRGB = System.Drawing.Color.Red;
colorScale.Criteria[1].Type = ConditionValueType.Percentile;
colorScale.Criteria[1].Value = "50";
colorScale.Criteria[2].FormatColorRGB = System.Drawing.Color.Blue;
colorScale.Criteria[2].Type = ConditionValueType.Percentile;
colorScale.Criteria[2].Value = "100";
//Save and Dispose.
workbook.SaveAs("ConditionalFormats.xlsx");
workbook.Close();
excelEngine.Dispose();
Methods
SetConditionCount(Int32)
Sets the number of IColorConditionValue objects in the collection. Supported values are 2 and 3.
Declaration
void SetConditionCount(int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | count | Number of conditions. |
Remarks
To know more about advanced conditional formatting Types refer this link.
Examples
The following code illustrates how to set the condition value count for color scale.
//Create a worksheet.
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Load data to Apply Conditional Formatting.
worksheet["A1"].Text = "ColorScale";
worksheet["A2"].Number = 10;
worksheet["A3"].Number = 20;
worksheet["A4"].Number = 30;
worksheet["A5"].Number = 40;
worksheet["A6"].Number = 50;
worksheet["A7"].Number = 60;
worksheet["A8"].Number = 70;
worksheet["A9"].Number = 80;
worksheet["A10"].Number = 90;
worksheet["A11"].Number = 100;
//Create instance of IConditonalFormat and IConditionalFormats.
IConditionalFormats formats = worksheet["A2:A11"].ConditionalFormats;
IConditionalFormat format = formats.AddCondition();
//Set FormatType as ColorScale.
format.FormatType = ExcelCFType.ColorScale;
IColorScale colorScale = format.ColorScale;
//Set 3 as count for color scale
colorScale.SetConditionCount(3);
//Save and Dispose.
workbook.SaveAs("ConditionalFormats.xlsx");
workbook.Close();
excelEngine.Dispose();