-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathColorScaleExample.cs
More file actions
41 lines (32 loc) · 1.53 KB
/
ColorScaleExample.cs
File metadata and controls
41 lines (32 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using OfficeOpenXml;
using System.Drawing;
using OfficeOpenXml.ConditionalFormatting;
using OfficeOpenXml.Drawing;
namespace EPPlusSamples.ConditionalFormatting
{
internal class ColorScaleExample
{
public static void Run(ExcelPackage pck)
{
var sheet = pck.Workbook.Worksheets.Add("ColorScales");
sheet.Cells["A1:B20"].Formula = "ROW()";
var twoScale = sheet.ConditionalFormatting.AddTwoColorScale("A1:A20");
var threeScale = sheet.ConditionalFormatting.AddThreeColorScale("B1:B20");
twoScale.LowValue.Color = Color.CadetBlue;
twoScale.HighValue.Color = ColorTranslator.FromHtml("#FF63BE7B");
threeScale.LowValue.Color = Color.DarkRed;
threeScale.MiddleValue.Color = Color.Orange;
threeScale.HighValue.Color = Color.ForestGreen;
//ColorSettings attribute allow you to use tint
threeScale.HighValue.ColorSettings.Tint = 0.80;
//It can also be used for alternative ways to set color. Note: Only last applied colorsetting matters.
//Except for Tint which works with all.
//threeScale.LowValue.ColorSettings.Theme = eThemeSchemeColor.Accent3;
//threeScale.MiddleValue.ColorSettings.Auto = true;
//threeScale.HighValue.ColorSettings.Index = 3;
threeScale.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Percentile;
threeScale.MiddleValue.Value = 50;
sheet.Cells.AutoFitColumns();
}
}
}