Skip to content

Commit a5e3591

Browse files
author
JanKallman
committed
Added support for Conditional Formatting IconSets and Databars.
Fixed bug with CF background color. And a few other small fixes --HG-- rename : EPPlus/ConditionalFormatting/ExcelConditionalFormattingValueObject.cs => EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs rename : EPPlus/ConditionalFormatting/ExcelConditionalFormattingValueObject.cs => EPPlus/ConditionalFormatting/ExcelConditionalFormattingIconDatabarValue.cs
1 parent 5a2882f commit a5e3591

31 files changed

+1682
-74
lines changed

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingDataBarGroup.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,34 @@
3434
using System.Text;
3535

3636
using OfficeOpenXml.ConditionalFormatting;
37+
using System.Drawing;
3738

3839
namespace OfficeOpenXml.ConditionalFormatting.Contracts
3940
{
4041
/// <summary>
4142
/// IExcelConditionalFormattingDataBar
4243
/// </summary>
4344
public interface IExcelConditionalFormattingDataBarGroup
44-
: IExcelConditionalFormattingRule
45+
: IExcelConditionalFormattingRule
4546
{
4647
#region Public Properties
47-
#endregion Public Properties
48+
/// <summary>
49+
/// ShowValue
50+
/// </summary>
51+
bool ShowValue { get; set; }
52+
/// <summary>
53+
/// Databar Low Value
54+
/// </summary>
55+
ExcelConditionalFormattingIconDataBarValue LowValue { get; }
56+
57+
/// <summary>
58+
/// Databar High Value
59+
/// </summary>
60+
ExcelConditionalFormattingIconDataBarValue HighValue { get; }
61+
/// <summary>
62+
/// The color of the databar
63+
/// </summary>
64+
Color Color { get; set;}
65+
#endregion Public Properties
4866
}
4967
}

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingFiveIconSet.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ namespace OfficeOpenXml.ConditionalFormatting.Contracts
3939
{
4040
/// <summary>
4141
/// IExcelConditionalFormattingFiveIconSet
42-
/// </summary>
43-
public interface IExcelConditionalFormattingFiveIconSet<T, I>
44-
: IExcelConditionalFormattingFourIconSet<T, I>
42+
/// </summary>eExcelconditionalFormatting4IconsSetType
43+
public interface IExcelConditionalFormattingFiveIconSet : IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting5IconsSetType>
4544
{
4645
#region Public Properties
4746
/// <summary>
4847
/// Icon5 (part of the 5 Icon Set)
4948
/// </summary>
50-
I Icon5 { get; set; }
49+
ExcelConditionalFormattingIconDataBarValue Icon5 { get; }
5150
#endregion Public Properties
5251
}
5352
}

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingFourIconSet.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ namespace OfficeOpenXml.ConditionalFormatting.Contracts
4040
/// <summary>
4141
/// IExcelConditionalFormattingFourIconSet
4242
/// </summary>
43-
public interface IExcelConditionalFormattingFourIconSet<T, I>
44-
: IExcelConditionalFormattingThreeIconSet<T, I>
43+
public interface IExcelConditionalFormattingFourIconSet<T> : IExcelConditionalFormattingThreeIconSet<T>
4544
{
4645
#region Public Properties
4746
/// <summary>
4847
/// Icon4 (part of the 4 ou 5 Icon Set)
4948
/// </summary>
50-
I Icon4 { get; set; }
49+
ExcelConditionalFormattingIconDataBarValue Icon4 { get; }
5150
#endregion Public Properties
5251
}
5352
}

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingThreeColorScale.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface IExcelConditionalFormattingThreeColorScale
4747
/// <summary>
4848
/// Three Color Scale Middle Value
4949
/// </summary>
50-
ExcelConditionalFormattingValueObject MiddleValue { get; set; }
50+
ExcelConditionalFormattingColorScaleValue MiddleValue { get; set; }
5151
#endregion Public Properties
5252
}
5353
}

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingThreeIconSet.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ namespace OfficeOpenXml.ConditionalFormatting.Contracts
4040
/// <summary>
4141
/// IExcelConditionalFormattingThreeIconSet
4242
/// </summary>
43-
public interface IExcelConditionalFormattingThreeIconSet<T, I>
43+
public interface IExcelConditionalFormattingThreeIconSet<T>
4444
: IExcelConditionalFormattingIconSetGroup<T>
4545
{
4646
#region Public Properties
4747
/// <summary>
4848
/// Icon1 (part of the 3, 4 ou 5 Icon Set)
4949
/// </summary>
50-
I Icon1 { get; set; }
50+
ExcelConditionalFormattingIconDataBarValue Icon1 { get; }
5151

5252
/// <summary>
5353
/// Icon2 (part of the 3, 4 ou 5 Icon Set)
5454
/// </summary>
55-
I Icon2 { get; set; }
55+
ExcelConditionalFormattingIconDataBarValue Icon2 { get; }
5656

5757
/// <summary>
5858
/// Icon3 (part of the 3, 4 ou 5 Icon Set)
5959
/// </summary>
60-
I Icon3 { get; set; }
60+
ExcelConditionalFormattingIconDataBarValue Icon3 { get; }
6161
#endregion Public Properties
6262
}
6363
}

EPPlus/ConditionalFormatting/Contracts/IExcelConditionalFormattingTwoColorScale.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public interface IExcelConditionalFormattingTwoColorScale
4747
/// <summary>
4848
/// Two Color Scale Low Value
4949
/// </summary>
50-
ExcelConditionalFormattingValueObject LowValue { get; set; }
50+
ExcelConditionalFormattingColorScaleValue LowValue { get; set; }
5151

5252
/// <summary>
5353
/// Two Color Scale High Value
5454
/// </summary>
55-
ExcelConditionalFormattingValueObject HighValue { get; set; }
55+
ExcelConditionalFormattingColorScaleValue HighValue { get; set; }
5656
#endregion Public Properties
5757
}
5858
}

EPPlus/ConditionalFormatting/Contracts/IRangeConditionalFormatting.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Eyal Seagull Conditional Formatting 2012-04-03
3030
*******************************************************************************/
3131
using OfficeOpenXml.ConditionalFormatting.Contracts;
32+
using System.Drawing;
3233

3334
namespace OfficeOpenXml.ConditionalFormatting
3435
{
@@ -284,6 +285,29 @@ public interface IRangeConditionalFormatting
284285
/// <returns></returns>
285286
IExcelConditionalFormattingTwoColorScale AddTwoColorScale();
286287

287-
//TODO: Add the DataBar and IconSet
288-
}
288+
/// <summary>
289+
/// Adds a <see cref="IExcelConditionalFormattingThreeIconSet"/> to the range
290+
/// </summary>
291+
/// <param name="IconSet"></param>
292+
/// <returns></returns>
293+
IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet(eExcelconditionalFormatting3IconsSetType IconSet);
294+
/// <summary>
295+
/// Adds a <see cref="IExcelConditionalFormattingFourIconSet"/> to the range
296+
/// </summary>
297+
/// <param name="IconSet"></param>
298+
/// <returns></returns>
299+
IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet(eExcelconditionalFormatting4IconsSetType IconSet);
300+
/// <summary>
301+
/// Adds a <see cref="IExcelConditionalFormattingFiveIconSet"/> to the range
302+
/// </summary>
303+
/// <param name="IconSet"></param>
304+
/// <returns></returns>
305+
IExcelConditionalFormattingFiveIconSet AddFiveIconSet(eExcelconditionalFormatting5IconsSetType IconSet);
306+
/// <summary>
307+
/// Adds a <see cref="IExcelConditionalFormattingDataBarGroup"/> to the range
308+
/// </summary>
309+
/// <param name="color"></param>
310+
/// <returns></returns>
311+
IExcelConditionalFormattingDataBarGroup AddDatabar(Color color);
312+
}
289313
}

EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using System.Xml;
3838
using OfficeOpenXml.ConditionalFormatting.Contracts;
3939
using System.Text.RegularExpressions;
40+
using System.Drawing;
4041

4142
namespace OfficeOpenXml.ConditionalFormatting
4243
{
@@ -163,7 +164,8 @@ internal ExcelConditionalFormattingCollection(
163164
cfRuleNode);
164165

165166
// Add the new rule to the list
166-
_rules.Add(cfRule);
167+
if(cfRule!=null)
168+
_rules.Add(cfRule);
167169
}
168170
}
169171
}
@@ -935,9 +937,62 @@ public IExcelConditionalFormattingTwoColorScale AddTwoColorScale(
935937
address);
936938
}
937939

938-
//TODO: Add the DataBar and IconSet
940+
/// <summary>
941+
/// Add ThreeIconSet Rule
942+
/// </summary>
943+
/// <param name="Address"></param>
944+
/// <returns></returns>
945+
public IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet(ExcelAddress Address, eExcelconditionalFormatting3IconsSetType IconSet)
946+
{
947+
var icon = (IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType>)AddRule(
948+
eExcelConditionalFormattingRuleType.ThreeIconSet,
949+
Address);
950+
icon.IconSet = IconSet;
951+
return icon;
952+
}
953+
/// <summary>
954+
/// Adds a FourIconSet rule
955+
/// </summary>
956+
/// <param name="Address"></param>
957+
/// <param name="IconSet"></param>
958+
/// <returns></returns>
959+
public IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet(ExcelAddress Address, eExcelconditionalFormatting4IconsSetType IconSet)
960+
{
961+
var icon = (IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType>)AddRule(
962+
eExcelConditionalFormattingRuleType.FourIconSet,
963+
Address);
964+
icon.IconSet = IconSet;
965+
return icon;
966+
}
967+
/// <summary>
968+
/// Adds a FiveIconSet rule
969+
/// </summary>
970+
/// <param name="Address"></param>
971+
/// <param name="IconSet"></param>
972+
/// <returns></returns>
973+
public IExcelConditionalFormattingFiveIconSet AddFiveIconSet(ExcelAddress Address, eExcelconditionalFormatting5IconsSetType IconSet)
974+
{
975+
var icon = (IExcelConditionalFormattingFiveIconSet)AddRule(
976+
eExcelConditionalFormattingRuleType.FiveIconSet,
977+
Address);
978+
icon.IconSet = IconSet;
979+
return icon;
980+
}
981+
/// <summary>
982+
/// Adds a databar rule
983+
/// </summary>
984+
/// <param name="Address"></param>
985+
/// <param name="color"></param>
986+
/// <returns></returns>
987+
public IExcelConditionalFormattingDataBarGroup AddDatabar(ExcelAddress Address, Color color)
988+
{
989+
var dataBar = (IExcelConditionalFormattingDataBarGroup)AddRule(
990+
eExcelConditionalFormattingRuleType.DataBar,
991+
Address);
992+
dataBar.Color=color;
993+
return dataBar;
994+
}
939995
#endregion Conditional Formatting Rules
940996

941-
/****************************************************************************************/
942997
}
943998
}

EPPlus/ConditionalFormatting/ExcelConditionalFormattingValueObject.cs renamed to EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace OfficeOpenXml.ConditionalFormatting
4545
/// 18.3.1.11 cfvo (Conditional Format Value Object)
4646
/// Describes the values of the interpolation points in a gradient scale.
4747
/// </summary>
48-
public class ExcelConditionalFormattingValueObject
48+
public class ExcelConditionalFormattingColorScaleValue
4949
: XmlHelper
5050
{
5151
/****************************************************************************************/
@@ -74,7 +74,7 @@ public class ExcelConditionalFormattingValueObject
7474
/// <param name="itemElementNode">The cfvo (§18.3.1.11) node parent. Can be any of the following:
7575
/// colorScale (§18.3.1.16); dataBar (§18.3.1.28); iconSet (§18.3.1.49)</param>
7676
/// <param name="namespaceManager"></param>
77-
internal ExcelConditionalFormattingValueObject(
77+
internal ExcelConditionalFormattingColorScaleValue(
7878
eExcelConditionalFormattingValueObjectPosition position,
7979
eExcelConditionalFormattingValueObjectType type,
8080
Color color,
@@ -161,7 +161,7 @@ internal ExcelConditionalFormattingValueObject(
161161
}
162162

163163
/// <summary>
164-
/// Initialize the <see cref="ExcelConditionalFormattingValueObject"/>
164+
/// Initialize the <see cref="ExcelConditionalFormattingColorScaleValue"/>
165165
/// </summary>
166166
/// <param name="position"></param>
167167
/// <param name="type"></param>
@@ -173,7 +173,7 @@ internal ExcelConditionalFormattingValueObject(
173173
/// <param name="address"></param>
174174
/// <param name="worksheet"></param>
175175
/// <param name="namespaceManager"></param>
176-
internal ExcelConditionalFormattingValueObject(
176+
internal ExcelConditionalFormattingColorScaleValue(
177177
eExcelConditionalFormattingValueObjectPosition position,
178178
eExcelConditionalFormattingValueObjectType type,
179179
Color color,
@@ -200,7 +200,7 @@ internal ExcelConditionalFormattingValueObject(
200200
}
201201

202202
/// <summary>
203-
/// Initialize the <see cref="ExcelConditionalFormattingValueObject"/>
203+
/// Initialize the <see cref="ExcelConditionalFormattingColorScaleValue"/>
204204
/// </summary>
205205
/// <param name="position"></param>
206206
/// <param name="type"></param>
@@ -210,7 +210,7 @@ internal ExcelConditionalFormattingValueObject(
210210
/// <param name="address"></param>
211211
/// <param name="worksheet"></param>
212212
/// <param name="namespaceManager"></param>
213-
internal ExcelConditionalFormattingValueObject(
213+
internal ExcelConditionalFormattingColorScaleValue(
214214
eExcelConditionalFormattingValueObjectPosition position,
215215
eExcelConditionalFormattingValueObjectType type,
216216
Color color,

0 commit comments

Comments
 (0)