1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * * Author Change Date
|
---|
28 | * ******************************************************************************
|
---|
29 | * Eyal Seagull Conditional Formatting 2012-04-03
|
---|
30 | *******************************************************************************/
|
---|
31 | using System;
|
---|
32 | using System.Collections.Generic;
|
---|
33 | using System.Linq;
|
---|
34 | using System.Text;
|
---|
35 | using System.Xml;
|
---|
36 | using OfficeOpenXml.Utils;
|
---|
37 | using OfficeOpenXml.ConditionalFormatting.Contracts;
|
---|
38 |
|
---|
39 | namespace OfficeOpenXml.ConditionalFormatting
|
---|
40 | {
|
---|
41 | /// <summary>
|
---|
42 | /// Factory class for ExcelConditionalFormatting.
|
---|
43 | /// </summary>
|
---|
44 | internal static class ExcelConditionalFormattingRuleFactory
|
---|
45 | {
|
---|
46 | public static ExcelConditionalFormattingRule Create(
|
---|
47 | eExcelConditionalFormattingRuleType type,
|
---|
48 | ExcelAddress address,
|
---|
49 | int priority,
|
---|
50 | ExcelWorksheet worksheet,
|
---|
51 | XmlNode itemElementNode)
|
---|
52 | {
|
---|
53 | Require.Argument(type);
|
---|
54 | Require.Argument(address).IsNotNull("address");
|
---|
55 | Require.Argument(priority).IsInRange(1, int.MaxValue, "priority");
|
---|
56 | Require.Argument(worksheet).IsNotNull("worksheet");
|
---|
57 |
|
---|
58 | // According the conditional formatting rule type
|
---|
59 | switch (type)
|
---|
60 | {
|
---|
61 | case eExcelConditionalFormattingRuleType.AboveAverage:
|
---|
62 | return new ExcelConditionalFormattingAboveAverage(
|
---|
63 | address,
|
---|
64 | priority,
|
---|
65 | worksheet,
|
---|
66 | itemElementNode);
|
---|
67 |
|
---|
68 | case eExcelConditionalFormattingRuleType.AboveOrEqualAverage:
|
---|
69 | return new ExcelConditionalFormattingAboveOrEqualAverage(
|
---|
70 | address,
|
---|
71 | priority,
|
---|
72 | worksheet,
|
---|
73 | itemElementNode);
|
---|
74 |
|
---|
75 | case eExcelConditionalFormattingRuleType.BelowAverage:
|
---|
76 | return new ExcelConditionalFormattingBelowAverage(
|
---|
77 | address,
|
---|
78 | priority,
|
---|
79 | worksheet,
|
---|
80 | itemElementNode);
|
---|
81 |
|
---|
82 | case eExcelConditionalFormattingRuleType.BelowOrEqualAverage:
|
---|
83 | return new ExcelConditionalFormattingBelowOrEqualAverage(
|
---|
84 | address,
|
---|
85 | priority,
|
---|
86 | worksheet,
|
---|
87 | itemElementNode);
|
---|
88 |
|
---|
89 | case eExcelConditionalFormattingRuleType.AboveStdDev:
|
---|
90 | return new ExcelConditionalFormattingAboveStdDev(
|
---|
91 | address,
|
---|
92 | priority,
|
---|
93 | worksheet,
|
---|
94 | itemElementNode);
|
---|
95 |
|
---|
96 | case eExcelConditionalFormattingRuleType.BelowStdDev:
|
---|
97 | return new ExcelConditionalFormattingBelowStdDev(
|
---|
98 | address,
|
---|
99 | priority,
|
---|
100 | worksheet,
|
---|
101 | itemElementNode);
|
---|
102 |
|
---|
103 | case eExcelConditionalFormattingRuleType.Bottom:
|
---|
104 | return new ExcelConditionalFormattingBottom(
|
---|
105 | address,
|
---|
106 | priority,
|
---|
107 | worksheet,
|
---|
108 | itemElementNode);
|
---|
109 |
|
---|
110 | case eExcelConditionalFormattingRuleType.BottomPercent:
|
---|
111 | return new ExcelConditionalFormattingBottomPercent(
|
---|
112 | address,
|
---|
113 | priority,
|
---|
114 | worksheet,
|
---|
115 | itemElementNode);
|
---|
116 |
|
---|
117 | case eExcelConditionalFormattingRuleType.Top:
|
---|
118 | return new ExcelConditionalFormattingTop(
|
---|
119 | address,
|
---|
120 | priority,
|
---|
121 | worksheet,
|
---|
122 | itemElementNode);
|
---|
123 |
|
---|
124 | case eExcelConditionalFormattingRuleType.TopPercent:
|
---|
125 | return new ExcelConditionalFormattingTopPercent(
|
---|
126 | address,
|
---|
127 | priority,
|
---|
128 | worksheet,
|
---|
129 | itemElementNode);
|
---|
130 |
|
---|
131 | case eExcelConditionalFormattingRuleType.Last7Days:
|
---|
132 | return new ExcelConditionalFormattingLast7Days(
|
---|
133 | address,
|
---|
134 | priority,
|
---|
135 | worksheet,
|
---|
136 | itemElementNode);
|
---|
137 |
|
---|
138 |
|
---|
139 | case eExcelConditionalFormattingRuleType.LastMonth:
|
---|
140 | return new ExcelConditionalFormattingLastMonth(
|
---|
141 | address,
|
---|
142 | priority,
|
---|
143 | worksheet,
|
---|
144 | itemElementNode);
|
---|
145 |
|
---|
146 | case eExcelConditionalFormattingRuleType.LastWeek:
|
---|
147 | return new ExcelConditionalFormattingLastWeek(
|
---|
148 | address,
|
---|
149 | priority,
|
---|
150 | worksheet,
|
---|
151 | itemElementNode);
|
---|
152 |
|
---|
153 | case eExcelConditionalFormattingRuleType.NextMonth:
|
---|
154 | return new ExcelConditionalFormattingNextMonth(
|
---|
155 | address,
|
---|
156 | priority,
|
---|
157 | worksheet,
|
---|
158 | itemElementNode);
|
---|
159 |
|
---|
160 | case eExcelConditionalFormattingRuleType.NextWeek:
|
---|
161 | return new ExcelConditionalFormattingNextWeek(
|
---|
162 | address,
|
---|
163 | priority,
|
---|
164 | worksheet,
|
---|
165 | itemElementNode);
|
---|
166 |
|
---|
167 | case eExcelConditionalFormattingRuleType.ThisMonth:
|
---|
168 | return new ExcelConditionalFormattingThisMonth(
|
---|
169 | address,
|
---|
170 | priority,
|
---|
171 | worksheet,
|
---|
172 | itemElementNode);
|
---|
173 |
|
---|
174 | case eExcelConditionalFormattingRuleType.ThisWeek:
|
---|
175 | return new ExcelConditionalFormattingThisWeek(
|
---|
176 | address,
|
---|
177 | priority,
|
---|
178 | worksheet,
|
---|
179 | itemElementNode);
|
---|
180 |
|
---|
181 | case eExcelConditionalFormattingRuleType.Today:
|
---|
182 | return new ExcelConditionalFormattingToday(
|
---|
183 | address,
|
---|
184 | priority,
|
---|
185 | worksheet,
|
---|
186 | itemElementNode);
|
---|
187 |
|
---|
188 | case eExcelConditionalFormattingRuleType.Tomorrow:
|
---|
189 | return new ExcelConditionalFormattingTomorrow(
|
---|
190 | address,
|
---|
191 | priority,
|
---|
192 | worksheet,
|
---|
193 | itemElementNode);
|
---|
194 |
|
---|
195 | case eExcelConditionalFormattingRuleType.Yesterday:
|
---|
196 | return new ExcelConditionalFormattingYesterday(
|
---|
197 | address,
|
---|
198 | priority,
|
---|
199 | worksheet,
|
---|
200 | itemElementNode);
|
---|
201 |
|
---|
202 | case eExcelConditionalFormattingRuleType.BeginsWith:
|
---|
203 | return new ExcelConditionalFormattingBeginsWith(
|
---|
204 | address,
|
---|
205 | priority,
|
---|
206 | worksheet,
|
---|
207 | itemElementNode);
|
---|
208 |
|
---|
209 | case eExcelConditionalFormattingRuleType.Between:
|
---|
210 | return new ExcelConditionalFormattingBetween(
|
---|
211 | address,
|
---|
212 | priority,
|
---|
213 | worksheet,
|
---|
214 | itemElementNode);
|
---|
215 |
|
---|
216 | case eExcelConditionalFormattingRuleType.ContainsBlanks:
|
---|
217 | return new ExcelConditionalFormattingContainsBlanks(
|
---|
218 | address,
|
---|
219 | priority,
|
---|
220 | worksheet,
|
---|
221 | itemElementNode);
|
---|
222 |
|
---|
223 | case eExcelConditionalFormattingRuleType.ContainsErrors:
|
---|
224 | return new ExcelConditionalFormattingContainsErrors(
|
---|
225 | address,
|
---|
226 | priority,
|
---|
227 | worksheet,
|
---|
228 | itemElementNode);
|
---|
229 |
|
---|
230 | case eExcelConditionalFormattingRuleType.ContainsText:
|
---|
231 | return new ExcelConditionalFormattingContainsText(
|
---|
232 | address,
|
---|
233 | priority,
|
---|
234 | worksheet,
|
---|
235 | itemElementNode);
|
---|
236 |
|
---|
237 | case eExcelConditionalFormattingRuleType.DuplicateValues:
|
---|
238 | return new ExcelConditionalFormattingDuplicateValues(
|
---|
239 | address,
|
---|
240 | priority,
|
---|
241 | worksheet,
|
---|
242 | itemElementNode);
|
---|
243 |
|
---|
244 | case eExcelConditionalFormattingRuleType.EndsWith:
|
---|
245 | return new ExcelConditionalFormattingEndsWith(
|
---|
246 | address,
|
---|
247 | priority,
|
---|
248 | worksheet,
|
---|
249 | itemElementNode);
|
---|
250 |
|
---|
251 | case eExcelConditionalFormattingRuleType.Equal:
|
---|
252 | return new ExcelConditionalFormattingEqual(
|
---|
253 | address,
|
---|
254 | priority,
|
---|
255 | worksheet,
|
---|
256 | itemElementNode);
|
---|
257 |
|
---|
258 | case eExcelConditionalFormattingRuleType.Expression:
|
---|
259 | return new ExcelConditionalFormattingExpression(
|
---|
260 | address,
|
---|
261 | priority,
|
---|
262 | worksheet,
|
---|
263 | itemElementNode);
|
---|
264 |
|
---|
265 | case eExcelConditionalFormattingRuleType.GreaterThan:
|
---|
266 | return new ExcelConditionalFormattingGreaterThan(
|
---|
267 | address,
|
---|
268 | priority,
|
---|
269 | worksheet,
|
---|
270 | itemElementNode);
|
---|
271 |
|
---|
272 | case eExcelConditionalFormattingRuleType.GreaterThanOrEqual:
|
---|
273 | return new ExcelConditionalFormattingGreaterThanOrEqual(
|
---|
274 | address,
|
---|
275 | priority,
|
---|
276 | worksheet,
|
---|
277 | itemElementNode);
|
---|
278 |
|
---|
279 | case eExcelConditionalFormattingRuleType.LessThan:
|
---|
280 | return new ExcelConditionalFormattingLessThan(
|
---|
281 | address,
|
---|
282 | priority,
|
---|
283 | worksheet,
|
---|
284 | itemElementNode);
|
---|
285 |
|
---|
286 | case eExcelConditionalFormattingRuleType.LessThanOrEqual:
|
---|
287 | return new ExcelConditionalFormattingLessThanOrEqual(
|
---|
288 | address,
|
---|
289 | priority,
|
---|
290 | worksheet,
|
---|
291 | itemElementNode);
|
---|
292 |
|
---|
293 | case eExcelConditionalFormattingRuleType.NotBetween:
|
---|
294 | return new ExcelConditionalFormattingNotBetween(
|
---|
295 | address,
|
---|
296 | priority,
|
---|
297 | worksheet,
|
---|
298 | itemElementNode);
|
---|
299 |
|
---|
300 | case eExcelConditionalFormattingRuleType.NotContainsBlanks:
|
---|
301 | return new ExcelConditionalFormattingNotContainsBlanks(
|
---|
302 | address,
|
---|
303 | priority,
|
---|
304 | worksheet,
|
---|
305 | itemElementNode);
|
---|
306 |
|
---|
307 | case eExcelConditionalFormattingRuleType.NotContainsErrors:
|
---|
308 | return new ExcelConditionalFormattingNotContainsErrors(
|
---|
309 | address,
|
---|
310 | priority,
|
---|
311 | worksheet,
|
---|
312 | itemElementNode);
|
---|
313 |
|
---|
314 | case eExcelConditionalFormattingRuleType.NotContainsText:
|
---|
315 | return new ExcelConditionalFormattingNotContainsText(
|
---|
316 | address,
|
---|
317 | priority,
|
---|
318 | worksheet,
|
---|
319 | itemElementNode);
|
---|
320 |
|
---|
321 | case eExcelConditionalFormattingRuleType.NotEqual:
|
---|
322 | return new ExcelConditionalFormattingNotEqual(
|
---|
323 | address,
|
---|
324 | priority,
|
---|
325 | worksheet,
|
---|
326 | itemElementNode);
|
---|
327 |
|
---|
328 | case eExcelConditionalFormattingRuleType.UniqueValues:
|
---|
329 | return new ExcelConditionalFormattingUniqueValues(
|
---|
330 | address,
|
---|
331 | priority,
|
---|
332 | worksheet,
|
---|
333 | itemElementNode);
|
---|
334 |
|
---|
335 | case eExcelConditionalFormattingRuleType.ThreeColorScale:
|
---|
336 | return new ExcelConditionalFormattingThreeColorScale(
|
---|
337 | address,
|
---|
338 | priority,
|
---|
339 | worksheet,
|
---|
340 | itemElementNode);
|
---|
341 |
|
---|
342 | case eExcelConditionalFormattingRuleType.TwoColorScale:
|
---|
343 | return new ExcelConditionalFormattingTwoColorScale(
|
---|
344 | address,
|
---|
345 | priority,
|
---|
346 | worksheet,
|
---|
347 | itemElementNode);
|
---|
348 | case eExcelConditionalFormattingRuleType.ThreeIconSet:
|
---|
349 | return new ExcelConditionalFormattingThreeIconSet(
|
---|
350 | address,
|
---|
351 | priority,
|
---|
352 | worksheet,
|
---|
353 | itemElementNode,
|
---|
354 | null);
|
---|
355 | case eExcelConditionalFormattingRuleType.FourIconSet:
|
---|
356 | return new ExcelConditionalFormattingFourIconSet(
|
---|
357 | address,
|
---|
358 | priority,
|
---|
359 | worksheet,
|
---|
360 | itemElementNode,
|
---|
361 | null);
|
---|
362 | case eExcelConditionalFormattingRuleType.FiveIconSet:
|
---|
363 | return new ExcelConditionalFormattingFiveIconSet(
|
---|
364 | address,
|
---|
365 | priority,
|
---|
366 | worksheet,
|
---|
367 | itemElementNode,
|
---|
368 | null);
|
---|
369 | case eExcelConditionalFormattingRuleType.DataBar:
|
---|
370 | return new ExcelConditionalFormattingDataBar(
|
---|
371 | eExcelConditionalFormattingRuleType.DataBar,
|
---|
372 | address,
|
---|
373 | priority,
|
---|
374 | worksheet,
|
---|
375 | itemElementNode,
|
---|
376 | null);
|
---|
377 |
|
---|
378 |
|
---|
379 | //TODO: Add DataBar
|
---|
380 | }
|
---|
381 |
|
---|
382 | throw new InvalidOperationException(
|
---|
383 | string.Format(
|
---|
384 | ExcelConditionalFormattingConstants.Errors.NonSupportedRuleType,
|
---|
385 | type.ToString()));
|
---|
386 | }
|
---|
387 | }
|
---|
388 | } |
---|