-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathIconsetsExample.cs
More file actions
67 lines (56 loc) · 2.61 KB
/
IconsetsExample.cs
File metadata and controls
67 lines (56 loc) · 2.61 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using OfficeOpenXml;
using OfficeOpenXml.ConditionalFormatting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EPPlusSamples.ConditionalFormatting
{
internal class IconsetsExample
{
public static void Run(ExcelPackage pck)
{
var sheet = pck.Workbook.Worksheets.Add("Iconsets");
//Fill sheet with data similar to wiki example
SheetInitalizeData(sheet);
var cfRule = sheet.ConditionalFormatting.AddThreeIconSet(sheet.Cells["D7:D13"], eExcelconditionalFormatting3IconsSetType.TrafficLights2);
//Normally order is red yellow green we want high values to be red so we reverse
cfRule.Reverse = true;
cfRule.Icon2.Type = eExcelConditionalFormattingValueObjectType.Formula;
cfRule.Icon2.Formula = "$E$2 * ($E$4 +1)";
cfRule.Icon3.Type = eExcelConditionalFormattingValueObjectType.Formula;
cfRule.Icon3.Formula = "$E$3";
//Below only available epplus7 onwards
//Switching out icons in a pre-existing iconset
var customIcons = sheet.ConditionalFormatting.AddFiveIconSet(sheet.Cells["G1:G13"], eExcelconditionalFormatting5IconsSetType.Quarters);
//Switch icons
customIcons.Icon1.CustomIcon = eExcelconditionalFormattingCustomIcon.RedCross;
customIcons.Icon3.CustomIcon = eExcelconditionalFormattingCustomIcon.HalfGoldStar;
customIcons.Icon5.CustomIcon = eExcelconditionalFormattingCustomIcon.RedDiamond;
//Add data to cells so icons show up.
sheet.Cells["G1:G13"].Formula = "ROW()";
sheet.Cells.AutoFitColumns();
}
private static void SheetInitalizeData(ExcelWorksheet sheet)
{
sheet.Cells["D7:D13"].Formula = "INT(RAND()*100)";
sheet.Cells["B2"].Value = "Speed Limit";
sheet.Cells["B3"].Value = "Drivers license suspended";
sheet.Cells["B4"].Value = "Tolerance";
sheet.Cells["E2"].Value = 50;
sheet.Cells["E3"].Value = 80;
sheet.Cells["E4"].Value = 0.08;
sheet.Cells["C6"].Value = "Driver";
sheet.Cells["D6"].Value = "Speed";
sheet.Cells["C7"].Value = "Peter";
sheet.Cells["C8"].Value = "Maria";
sheet.Cells["C9"].Value = "John";
sheet.Cells["C10"].Value = "Bob";
sheet.Cells["C11"].Value = "Anna";
sheet.Cells["C12"].Value = "Cecilia";
sheet.Cells["C13"].Value = "Joe";
}
}
}