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.Collections;
|
---|
36 | using OfficeOpenXml.Utils;
|
---|
37 | using System.Xml;
|
---|
38 | using OfficeOpenXml.ConditionalFormatting.Contracts;
|
---|
39 | using System.Text.RegularExpressions;
|
---|
40 | using System.Drawing;
|
---|
41 |
|
---|
42 | namespace OfficeOpenXml.ConditionalFormatting
|
---|
43 | {
|
---|
44 | /// <summary>
|
---|
45 | /// Collection of <see cref="ExcelConditionalFormattingRule"/>.
|
---|
46 | /// This class is providing the API for EPPlus conditional formatting.
|
---|
47 | /// </summary>
|
---|
48 | /// <remarks>
|
---|
49 | /// <para>
|
---|
50 | /// The public methods of this class (Add[...]ConditionalFormatting) will create a ConditionalFormatting/CfRule entry in the worksheet. When this
|
---|
51 | /// Conditional Formatting has been created changes to the properties will affect the workbook immediately.
|
---|
52 | /// </para>
|
---|
53 | /// <para>
|
---|
54 | /// Each type of Conditional Formatting Rule has diferente set of properties.
|
---|
55 | /// </para>
|
---|
56 | /// <code>
|
---|
57 | /// // Add a Three Color Scale conditional formatting
|
---|
58 | /// var cf = worksheet.ConditionalFormatting.AddThreeColorScale(new ExcelAddress("A1:C10"));
|
---|
59 | /// // Set the conditional formatting properties
|
---|
60 | /// cf.LowValue.Type = ExcelConditionalFormattingValueObjectType.Min;
|
---|
61 | /// cf.LowValue.Color = Color.White;
|
---|
62 | /// cf.MiddleValue.Type = ExcelConditionalFormattingValueObjectType.Percent;
|
---|
63 | /// cf.MiddleValue.Value = 50;
|
---|
64 | /// cf.MiddleValue.Color = Color.Blue;
|
---|
65 | /// cf.HighValue.Type = ExcelConditionalFormattingValueObjectType.Max;
|
---|
66 | /// cf.HighValue.Color = Color.Black;
|
---|
67 | /// </code>
|
---|
68 | /// </remarks>
|
---|
69 | public class ExcelConditionalFormattingCollection
|
---|
70 | : XmlHelper,
|
---|
71 | IEnumerable<IExcelConditionalFormattingRule>
|
---|
72 | {
|
---|
73 | /****************************************************************************************/
|
---|
74 |
|
---|
75 | #region Private Properties
|
---|
76 | private List<IExcelConditionalFormattingRule> _rules = new List<IExcelConditionalFormattingRule>();
|
---|
77 | private ExcelWorksheet _worksheet = null;
|
---|
78 | #endregion Private Properties
|
---|
79 |
|
---|
80 | /****************************************************************************************/
|
---|
81 |
|
---|
82 | #region Constructors
|
---|
83 | /// <summary>
|
---|
84 | /// Initialize the <see cref="ExcelConditionalFormattingCollection"/>
|
---|
85 | /// </summary>
|
---|
86 | /// <param name="worksheet"></param>
|
---|
87 | internal ExcelConditionalFormattingCollection(
|
---|
88 | ExcelWorksheet worksheet)
|
---|
89 | : base(
|
---|
90 | worksheet.NameSpaceManager,
|
---|
91 | worksheet.WorksheetXml.DocumentElement)
|
---|
92 | {
|
---|
93 | Require.Argument(worksheet).IsNotNull("worksheet");
|
---|
94 |
|
---|
95 | _worksheet = worksheet;
|
---|
96 | SchemaNodeOrder = _worksheet.SchemaNodeOrder;
|
---|
97 |
|
---|
98 | // Look for all the <conditionalFormatting>
|
---|
99 | var conditionalFormattingNodes = TopNode.SelectNodes(
|
---|
100 | "//" + ExcelConditionalFormattingConstants.Paths.ConditionalFormatting,
|
---|
101 | _worksheet.NameSpaceManager);
|
---|
102 |
|
---|
103 | // Check if we found at least 1 node
|
---|
104 | if ((conditionalFormattingNodes != null)
|
---|
105 | && (conditionalFormattingNodes.Count > 0))
|
---|
106 | {
|
---|
107 | // Foreach <conditionalFormatting>
|
---|
108 | foreach (XmlNode conditionalFormattingNode in conditionalFormattingNodes)
|
---|
109 | {
|
---|
110 | // Check if @sqref attribute exists
|
---|
111 | if (conditionalFormattingNode.Attributes[ExcelConditionalFormattingConstants.Attributes.Sqref] == null)
|
---|
112 | {
|
---|
113 | throw new Exception(
|
---|
114 | ExcelConditionalFormattingConstants.Errors.MissingSqrefAttribute);
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Get the @sqref attribute
|
---|
118 | ExcelAddress address = new ExcelAddress(
|
---|
119 | conditionalFormattingNode.Attributes[ExcelConditionalFormattingConstants.Attributes.Sqref].Value);
|
---|
120 |
|
---|
121 | // Check for all the <cfRules> nodes and load them
|
---|
122 | var cfRuleNodes = conditionalFormattingNode.SelectNodes(
|
---|
123 | ExcelConditionalFormattingConstants.Paths.CfRule,
|
---|
124 | _worksheet.NameSpaceManager);
|
---|
125 |
|
---|
126 | // Foreach <cfRule> inside the current <conditionalFormatting>
|
---|
127 | foreach (XmlNode cfRuleNode in cfRuleNodes)
|
---|
128 | {
|
---|
129 | // Check if @type attribute exists
|
---|
130 | if (cfRuleNode.Attributes[ExcelConditionalFormattingConstants.Attributes.Type] == null)
|
---|
131 | {
|
---|
132 | throw new Exception(
|
---|
133 | ExcelConditionalFormattingConstants.Errors.MissingTypeAttribute);
|
---|
134 | }
|
---|
135 |
|
---|
136 | // Check if @priority attribute exists
|
---|
137 | if (cfRuleNode.Attributes[ExcelConditionalFormattingConstants.Attributes.Priority] == null)
|
---|
138 | {
|
---|
139 | throw new Exception(
|
---|
140 | ExcelConditionalFormattingConstants.Errors.MissingPriorityAttribute);
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Get the <cfRule> main attributes
|
---|
144 | string typeAttribute = ExcelConditionalFormattingHelper.GetAttributeString(
|
---|
145 | cfRuleNode,
|
---|
146 | ExcelConditionalFormattingConstants.Attributes.Type);
|
---|
147 |
|
---|
148 | int priority = ExcelConditionalFormattingHelper.GetAttributeInt(
|
---|
149 | cfRuleNode,
|
---|
150 | ExcelConditionalFormattingConstants.Attributes.Priority);
|
---|
151 |
|
---|
152 | // Transform the @type attribute to EPPlus Rule Type (slighty diferente)
|
---|
153 | var type = ExcelConditionalFormattingRuleType.GetTypeByAttrbiute(
|
---|
154 | typeAttribute,
|
---|
155 | cfRuleNode,
|
---|
156 | _worksheet.NameSpaceManager);
|
---|
157 |
|
---|
158 | // Create the Rule according to the correct type, address and priority
|
---|
159 | var cfRule = ExcelConditionalFormattingRuleFactory.Create(
|
---|
160 | type,
|
---|
161 | address,
|
---|
162 | priority,
|
---|
163 | _worksheet,
|
---|
164 | cfRuleNode);
|
---|
165 |
|
---|
166 | // Add the new rule to the list
|
---|
167 | if(cfRule!=null)
|
---|
168 | _rules.Add(cfRule);
|
---|
169 | }
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 | #endregion Constructors
|
---|
174 |
|
---|
175 | /****************************************************************************************/
|
---|
176 |
|
---|
177 | #region Methods
|
---|
178 | /// <summary>
|
---|
179 | ///
|
---|
180 | /// </summary>
|
---|
181 | private void EnsureRootElementExists()
|
---|
182 | {
|
---|
183 | // Find the <worksheet> node
|
---|
184 | if (_worksheet.WorksheetXml.DocumentElement == null)
|
---|
185 | {
|
---|
186 | throw new Exception(
|
---|
187 | ExcelConditionalFormattingConstants.Errors.MissingWorksheetNode);
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | /// <summary>
|
---|
192 | /// GetRootNode
|
---|
193 | /// </summary>
|
---|
194 | /// <returns></returns>
|
---|
195 | private XmlNode GetRootNode()
|
---|
196 | {
|
---|
197 | EnsureRootElementExists();
|
---|
198 | return _worksheet.WorksheetXml.DocumentElement;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /// <summary>
|
---|
202 | /// Validates address - not empty (collisions are allowded)
|
---|
203 | /// </summary>
|
---|
204 | /// <param name="address"></param>
|
---|
205 | /// <returns></returns>
|
---|
206 | private ExcelAddress ValidateAddress(
|
---|
207 | ExcelAddress address)
|
---|
208 | {
|
---|
209 | Require.Argument(address).IsNotNull("address");
|
---|
210 |
|
---|
211 | //TODO: Are there any other validation we need to do?
|
---|
212 | return address;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /// <summary>
|
---|
216 | /// Get the next priority sequencial number
|
---|
217 | /// </summary>
|
---|
218 | /// <returns></returns>
|
---|
219 | private int GetNextPriority()
|
---|
220 | {
|
---|
221 | // Consider zero as the last priority when we have no CF rules
|
---|
222 | int lastPriority = 0;
|
---|
223 |
|
---|
224 | // Search for the last priority
|
---|
225 | foreach (var cfRule in _rules)
|
---|
226 | {
|
---|
227 | if (cfRule.Priority > lastPriority)
|
---|
228 | {
|
---|
229 | lastPriority = cfRule.Priority;
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | // Our next priority is the last plus one
|
---|
234 | return lastPriority + 1;
|
---|
235 | }
|
---|
236 | #endregion Methods
|
---|
237 |
|
---|
238 | /****************************************************************************************/
|
---|
239 |
|
---|
240 | #region IEnumerable<IExcelConditionalFormatting>
|
---|
241 | /// <summary>
|
---|
242 | /// Number of validations
|
---|
243 | /// </summary>
|
---|
244 | public int Count
|
---|
245 | {
|
---|
246 | get { return _rules.Count; }
|
---|
247 | }
|
---|
248 |
|
---|
249 | /// <summary>
|
---|
250 | /// Index operator, returns by 0-based index
|
---|
251 | /// </summary>
|
---|
252 | /// <param name="index"></param>
|
---|
253 | /// <returns></returns>
|
---|
254 | public IExcelConditionalFormattingRule this[int index]
|
---|
255 | {
|
---|
256 | get { return _rules[index]; }
|
---|
257 | set { _rules[index] = value; }
|
---|
258 | }
|
---|
259 |
|
---|
260 | /// <summary>
|
---|
261 | /// Get the 'cfRule' enumerator
|
---|
262 | /// </summary>
|
---|
263 | /// <returns></returns>
|
---|
264 | IEnumerator<IExcelConditionalFormattingRule> IEnumerable<IExcelConditionalFormattingRule>.GetEnumerator()
|
---|
265 | {
|
---|
266 | return _rules.GetEnumerator();
|
---|
267 | }
|
---|
268 |
|
---|
269 | /// <summary>
|
---|
270 | /// Get the 'cfRule' enumerator
|
---|
271 | /// </summary>
|
---|
272 | /// <returns></returns>
|
---|
273 | IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
---|
274 | {
|
---|
275 | return _rules.GetEnumerator();
|
---|
276 | }
|
---|
277 |
|
---|
278 | /// <summary>
|
---|
279 | /// Removes all 'cfRule' from the collection and from the XML.
|
---|
280 | /// <remarks>
|
---|
281 | /// This is the same as removing all the 'conditionalFormatting' nodes.
|
---|
282 | /// </remarks>
|
---|
283 | /// </summary>
|
---|
284 | public void RemoveAll()
|
---|
285 | {
|
---|
286 | // Look for all the <conditionalFormatting> nodes
|
---|
287 | var conditionalFormattingNodes = TopNode.SelectNodes(
|
---|
288 | "//" + ExcelConditionalFormattingConstants.Paths.ConditionalFormatting,
|
---|
289 | _worksheet.NameSpaceManager);
|
---|
290 |
|
---|
291 | // Remove all the <conditionalFormatting> nodes one by one
|
---|
292 | foreach (XmlNode conditionalFormattingNode in conditionalFormattingNodes)
|
---|
293 | {
|
---|
294 | conditionalFormattingNode.ParentNode.RemoveChild(conditionalFormattingNode);
|
---|
295 | }
|
---|
296 |
|
---|
297 | // Clear the <cfRule> item list
|
---|
298 | _rules.Clear();
|
---|
299 | }
|
---|
300 |
|
---|
301 | /// <summary>
|
---|
302 | /// Remove a Conditional Formatting Rule by its object
|
---|
303 | /// </summary>
|
---|
304 | /// <param name="item"></param>
|
---|
305 | public void Remove(
|
---|
306 | IExcelConditionalFormattingRule item)
|
---|
307 | {
|
---|
308 | Require.Argument(item).IsNotNull("item");
|
---|
309 |
|
---|
310 | try
|
---|
311 | {
|
---|
312 | // Point to the parent node
|
---|
313 | var oldParentNode = item.Node.ParentNode;
|
---|
314 |
|
---|
315 | // Remove the <cfRule> from the old <conditionalFormatting> parent node
|
---|
316 | oldParentNode.RemoveChild(item.Node);
|
---|
317 |
|
---|
318 | // Check if the old <conditionalFormatting> parent node has <cfRule> node inside it
|
---|
319 | if (!oldParentNode.HasChildNodes)
|
---|
320 | {
|
---|
321 | // Remove the old parent node
|
---|
322 | oldParentNode.ParentNode.RemoveChild(oldParentNode);
|
---|
323 | }
|
---|
324 |
|
---|
325 | _rules.Remove(item);
|
---|
326 | }
|
---|
327 | catch
|
---|
328 | {
|
---|
329 | throw new Exception(
|
---|
330 | ExcelConditionalFormattingConstants.Errors.InvalidRemoveRuleOperation);
|
---|
331 | }
|
---|
332 | }
|
---|
333 |
|
---|
334 | /// <summary>
|
---|
335 | /// Remove a Conditional Formatting Rule by its 0-based index
|
---|
336 | /// </summary>
|
---|
337 | /// <param name="index"></param>
|
---|
338 | public void RemoveAt(
|
---|
339 | int index)
|
---|
340 | {
|
---|
341 | Require.Argument(index).IsInRange(0, this.Count - 1, "index");
|
---|
342 |
|
---|
343 | Remove(this[index]);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /// <summary>
|
---|
347 | /// Remove a Conditional Formatting Rule by its priority
|
---|
348 | /// </summary>
|
---|
349 | /// <param name="priority"></param>
|
---|
350 | public void RemoveByPriority(
|
---|
351 | int priority)
|
---|
352 | {
|
---|
353 | try
|
---|
354 | {
|
---|
355 | Remove(RulesByPriority(priority));
|
---|
356 | }
|
---|
357 | catch
|
---|
358 | {
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | /// <summary>
|
---|
363 | /// Get a rule by its priority
|
---|
364 | /// </summary>
|
---|
365 | /// <param name="priority"></param>
|
---|
366 | /// <returns></returns>
|
---|
367 | public IExcelConditionalFormattingRule RulesByPriority(
|
---|
368 | int priority)
|
---|
369 | {
|
---|
370 | return _rules.Find(x => x.Priority == priority);
|
---|
371 | }
|
---|
372 | #endregion IEnumerable<IExcelConditionalFormatting>
|
---|
373 |
|
---|
374 | /****************************************************************************************/
|
---|
375 |
|
---|
376 | #region Conditional Formatting Rules
|
---|
377 | /// <summary>
|
---|
378 | /// Add rule (internal)
|
---|
379 | /// </summary>
|
---|
380 | /// <param name="type"></param>
|
---|
381 | /// <param name="address"></param>
|
---|
382 | /// <returns></returns>F
|
---|
383 | internal IExcelConditionalFormattingRule AddRule(
|
---|
384 | eExcelConditionalFormattingRuleType type,
|
---|
385 | ExcelAddress address)
|
---|
386 | {
|
---|
387 | Require.Argument(address).IsNotNull("address");
|
---|
388 |
|
---|
389 | address = ValidateAddress(address);
|
---|
390 | EnsureRootElementExists();
|
---|
391 |
|
---|
392 | // Create the Rule according to the correct type, address and priority
|
---|
393 | IExcelConditionalFormattingRule cfRule = ExcelConditionalFormattingRuleFactory.Create(
|
---|
394 | type,
|
---|
395 | address,
|
---|
396 | GetNextPriority(),
|
---|
397 | _worksheet,
|
---|
398 | null);
|
---|
399 |
|
---|
400 | // Add the newly created rule to the list
|
---|
401 | _rules.Add(cfRule);
|
---|
402 |
|
---|
403 | // Return the newly created rule
|
---|
404 | return cfRule;
|
---|
405 | }
|
---|
406 |
|
---|
407 | /// <summary>
|
---|
408 | /// Add AboveAverage Rule
|
---|
409 | /// </summary>
|
---|
410 | /// <param name="address"></param>
|
---|
411 | /// <returns></returns>
|
---|
412 | public IExcelConditionalFormattingAverageGroup AddAboveAverage(
|
---|
413 | ExcelAddress address)
|
---|
414 | {
|
---|
415 | return (IExcelConditionalFormattingAverageGroup)AddRule(
|
---|
416 | eExcelConditionalFormattingRuleType.AboveAverage,
|
---|
417 | address);
|
---|
418 | }
|
---|
419 |
|
---|
420 | /// <summary>
|
---|
421 | /// Add AboveOrEqualAverage Rule
|
---|
422 | /// </summary>
|
---|
423 | /// <param name="address"></param>
|
---|
424 | /// <returns></returns>
|
---|
425 | public IExcelConditionalFormattingAverageGroup AddAboveOrEqualAverage(
|
---|
426 | ExcelAddress address)
|
---|
427 | {
|
---|
428 | return (IExcelConditionalFormattingAverageGroup)AddRule(
|
---|
429 | eExcelConditionalFormattingRuleType.AboveOrEqualAverage,
|
---|
430 | address);
|
---|
431 | }
|
---|
432 |
|
---|
433 | /// <summary>
|
---|
434 | /// Add BelowAverage Rule
|
---|
435 | /// </summary>
|
---|
436 | /// <param name="address"></param>
|
---|
437 | /// <returns></returns>
|
---|
438 | public IExcelConditionalFormattingAverageGroup AddBelowAverage(
|
---|
439 | ExcelAddress address)
|
---|
440 | {
|
---|
441 | return (IExcelConditionalFormattingAverageGroup)AddRule(
|
---|
442 | eExcelConditionalFormattingRuleType.BelowAverage,
|
---|
443 | address);
|
---|
444 | }
|
---|
445 |
|
---|
446 | /// <summary>
|
---|
447 | /// Add BelowOrEqualAverage Rule
|
---|
448 | /// </summary>
|
---|
449 | /// <param name="address"></param>
|
---|
450 | /// <returns></returns>
|
---|
451 | public IExcelConditionalFormattingAverageGroup AddBelowOrEqualAverage(
|
---|
452 | ExcelAddress address)
|
---|
453 | {
|
---|
454 | return (IExcelConditionalFormattingAverageGroup)AddRule(
|
---|
455 | eExcelConditionalFormattingRuleType.BelowOrEqualAverage,
|
---|
456 | address);
|
---|
457 | }
|
---|
458 |
|
---|
459 | /// <summary>
|
---|
460 | /// Add AboveStdDev Rule
|
---|
461 | /// </summary>
|
---|
462 | /// <param name="address"></param>
|
---|
463 | /// <returns></returns>
|
---|
464 | public IExcelConditionalFormattingStdDevGroup AddAboveStdDev(
|
---|
465 | ExcelAddress address)
|
---|
466 | {
|
---|
467 | return (IExcelConditionalFormattingStdDevGroup)AddRule(
|
---|
468 | eExcelConditionalFormattingRuleType.AboveStdDev,
|
---|
469 | address);
|
---|
470 | }
|
---|
471 |
|
---|
472 | /// <summary>
|
---|
473 | /// Add BelowStdDev Rule
|
---|
474 | /// </summary>
|
---|
475 | /// <param name="address"></param>
|
---|
476 | /// <returns></returns>
|
---|
477 | public IExcelConditionalFormattingStdDevGroup AddBelowStdDev(
|
---|
478 | ExcelAddress address)
|
---|
479 | {
|
---|
480 | return (IExcelConditionalFormattingStdDevGroup)AddRule(
|
---|
481 | eExcelConditionalFormattingRuleType.BelowStdDev,
|
---|
482 | address);
|
---|
483 | }
|
---|
484 |
|
---|
485 | /// <summary>
|
---|
486 | /// Add Bottom Rule
|
---|
487 | /// </summary>
|
---|
488 | /// <param name="address"></param>
|
---|
489 | /// <returns></returns>
|
---|
490 | public IExcelConditionalFormattingTopBottomGroup AddBottom(
|
---|
491 | ExcelAddress address)
|
---|
492 | {
|
---|
493 | return (IExcelConditionalFormattingTopBottomGroup)AddRule(
|
---|
494 | eExcelConditionalFormattingRuleType.Bottom,
|
---|
495 | address);
|
---|
496 | }
|
---|
497 |
|
---|
498 | /// <summary>
|
---|
499 | /// Add BottomPercent Rule
|
---|
500 | /// </summary>
|
---|
501 | /// <param name="address"></param>
|
---|
502 | /// <returns></returns>
|
---|
503 | public IExcelConditionalFormattingTopBottomGroup AddBottomPercent(
|
---|
504 | ExcelAddress address)
|
---|
505 | {
|
---|
506 | return (IExcelConditionalFormattingTopBottomGroup)AddRule(
|
---|
507 | eExcelConditionalFormattingRuleType.BottomPercent,
|
---|
508 | address);
|
---|
509 | }
|
---|
510 |
|
---|
511 | /// <summary>
|
---|
512 | /// Add Top Rule
|
---|
513 | /// </summary>
|
---|
514 | /// <param name="address"></param>
|
---|
515 | /// <returns></returns>
|
---|
516 | public IExcelConditionalFormattingTopBottomGroup AddTop(
|
---|
517 | ExcelAddress address)
|
---|
518 | {
|
---|
519 | return (IExcelConditionalFormattingTopBottomGroup)AddRule(
|
---|
520 | eExcelConditionalFormattingRuleType.Top,
|
---|
521 | address);
|
---|
522 | }
|
---|
523 |
|
---|
524 | /// <summary>
|
---|
525 | /// Add TopPercent Rule
|
---|
526 | /// </summary>
|
---|
527 | /// <param name="address"></param>
|
---|
528 | /// <returns></returns>
|
---|
529 | public IExcelConditionalFormattingTopBottomGroup AddTopPercent(
|
---|
530 | ExcelAddress address)
|
---|
531 | {
|
---|
532 | return (IExcelConditionalFormattingTopBottomGroup)AddRule(
|
---|
533 | eExcelConditionalFormattingRuleType.TopPercent,
|
---|
534 | address);
|
---|
535 | }
|
---|
536 |
|
---|
537 | /// <summary>
|
---|
538 | /// Add Last7Days Rule
|
---|
539 | /// </summary>
|
---|
540 | /// <param name="address"></param>
|
---|
541 | /// <returns></returns>
|
---|
542 | public IExcelConditionalFormattingTimePeriodGroup AddLast7Days(
|
---|
543 | ExcelAddress address)
|
---|
544 | {
|
---|
545 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
546 | eExcelConditionalFormattingRuleType.Last7Days,
|
---|
547 | address);
|
---|
548 | }
|
---|
549 |
|
---|
550 | /// <summary>
|
---|
551 | /// Add LastMonth Rule
|
---|
552 | /// </summary>
|
---|
553 | /// <param name="address"></param>
|
---|
554 | /// <returns></returns>
|
---|
555 | public IExcelConditionalFormattingTimePeriodGroup AddLastMonth(
|
---|
556 | ExcelAddress address)
|
---|
557 | {
|
---|
558 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
559 | eExcelConditionalFormattingRuleType.LastMonth,
|
---|
560 | address);
|
---|
561 | }
|
---|
562 |
|
---|
563 | /// <summary>
|
---|
564 | /// Add LastWeek Rule
|
---|
565 | /// </summary>
|
---|
566 | /// <param name="address"></param>
|
---|
567 | /// <returns></returns>
|
---|
568 | public IExcelConditionalFormattingTimePeriodGroup AddLastWeek(
|
---|
569 | ExcelAddress address)
|
---|
570 | {
|
---|
571 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
572 | eExcelConditionalFormattingRuleType.LastWeek,
|
---|
573 | address);
|
---|
574 | }
|
---|
575 |
|
---|
576 | /// <summary>
|
---|
577 | /// Add NextMonth Rule
|
---|
578 | /// </summary>
|
---|
579 | /// <param name="address"></param>
|
---|
580 | /// <returns></returns>
|
---|
581 | public IExcelConditionalFormattingTimePeriodGroup AddNextMonth(
|
---|
582 | ExcelAddress address)
|
---|
583 | {
|
---|
584 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
585 | eExcelConditionalFormattingRuleType.NextMonth,
|
---|
586 | address);
|
---|
587 | }
|
---|
588 |
|
---|
589 | /// <summary>
|
---|
590 | /// Add NextWeek Rule
|
---|
591 | /// </summary>
|
---|
592 | /// <param name="address"></param>
|
---|
593 | /// <returns></returns>
|
---|
594 | public IExcelConditionalFormattingTimePeriodGroup AddNextWeek(
|
---|
595 | ExcelAddress address)
|
---|
596 | {
|
---|
597 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
598 | eExcelConditionalFormattingRuleType.NextWeek,
|
---|
599 | address);
|
---|
600 | }
|
---|
601 |
|
---|
602 | /// <summary>
|
---|
603 | /// Add ThisMonth Rule
|
---|
604 | /// </summary>
|
---|
605 | /// <param name="address"></param>
|
---|
606 | /// <returns></returns>
|
---|
607 | public IExcelConditionalFormattingTimePeriodGroup AddThisMonth(
|
---|
608 | ExcelAddress address)
|
---|
609 | {
|
---|
610 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
611 | eExcelConditionalFormattingRuleType.ThisMonth,
|
---|
612 | address);
|
---|
613 | }
|
---|
614 |
|
---|
615 | /// <summary>
|
---|
616 | /// Add ThisWeek Rule
|
---|
617 | /// </summary>
|
---|
618 | /// <param name="address"></param>
|
---|
619 | /// <returns></returns>
|
---|
620 | public IExcelConditionalFormattingTimePeriodGroup AddThisWeek(
|
---|
621 | ExcelAddress address)
|
---|
622 | {
|
---|
623 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
624 | eExcelConditionalFormattingRuleType.ThisWeek,
|
---|
625 | address);
|
---|
626 | }
|
---|
627 |
|
---|
628 | /// <summary>
|
---|
629 | /// Add Today Rule
|
---|
630 | /// </summary>
|
---|
631 | /// <param name="address"></param>
|
---|
632 | /// <returns></returns>
|
---|
633 | public IExcelConditionalFormattingTimePeriodGroup AddToday(
|
---|
634 | ExcelAddress address)
|
---|
635 | {
|
---|
636 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
637 | eExcelConditionalFormattingRuleType.Today,
|
---|
638 | address);
|
---|
639 | }
|
---|
640 |
|
---|
641 | /// <summary>
|
---|
642 | /// Add Tomorrow Rule
|
---|
643 | /// </summary>
|
---|
644 | /// <param name="address"></param>
|
---|
645 | /// <returns></returns>
|
---|
646 | public IExcelConditionalFormattingTimePeriodGroup AddTomorrow(
|
---|
647 | ExcelAddress address)
|
---|
648 | {
|
---|
649 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
650 | eExcelConditionalFormattingRuleType.Tomorrow,
|
---|
651 | address);
|
---|
652 | }
|
---|
653 |
|
---|
654 | /// <summary>
|
---|
655 | /// Add Yesterday Rule
|
---|
656 | /// </summary>
|
---|
657 | /// <param name="address"></param>
|
---|
658 | /// <returns></returns>
|
---|
659 | public IExcelConditionalFormattingTimePeriodGroup AddYesterday(
|
---|
660 | ExcelAddress address)
|
---|
661 | {
|
---|
662 | return (IExcelConditionalFormattingTimePeriodGroup)AddRule(
|
---|
663 | eExcelConditionalFormattingRuleType.Yesterday,
|
---|
664 | address);
|
---|
665 | }
|
---|
666 |
|
---|
667 | /// <summary>
|
---|
668 | /// Add BeginsWith Rule
|
---|
669 | /// </summary>
|
---|
670 | /// <param name="address"></param>
|
---|
671 | /// <returns></returns>
|
---|
672 | public IExcelConditionalFormattingBeginsWith AddBeginsWith(
|
---|
673 | ExcelAddress address)
|
---|
674 | {
|
---|
675 | return (IExcelConditionalFormattingBeginsWith)AddRule(
|
---|
676 | eExcelConditionalFormattingRuleType.BeginsWith,
|
---|
677 | address);
|
---|
678 | }
|
---|
679 |
|
---|
680 | /// <summary>
|
---|
681 | /// Add Between Rule
|
---|
682 | /// </summary>
|
---|
683 | /// <param name="address"></param>
|
---|
684 | /// <returns></returns>
|
---|
685 | public IExcelConditionalFormattingBetween AddBetween(
|
---|
686 | ExcelAddress address)
|
---|
687 | {
|
---|
688 | return (IExcelConditionalFormattingBetween)AddRule(
|
---|
689 | eExcelConditionalFormattingRuleType.Between,
|
---|
690 | address);
|
---|
691 | }
|
---|
692 |
|
---|
693 | /// <summary>
|
---|
694 | /// Add ContainsBlanks Rule
|
---|
695 | /// </summary>
|
---|
696 | /// <param name="address"></param>
|
---|
697 | /// <returns></returns>
|
---|
698 | public IExcelConditionalFormattingContainsBlanks AddContainsBlanks(
|
---|
699 | ExcelAddress address)
|
---|
700 | {
|
---|
701 | return (IExcelConditionalFormattingContainsBlanks)AddRule(
|
---|
702 | eExcelConditionalFormattingRuleType.ContainsBlanks,
|
---|
703 | address);
|
---|
704 | }
|
---|
705 |
|
---|
706 | /// <summary>
|
---|
707 | /// Add ContainsErrors Rule
|
---|
708 | /// </summary>
|
---|
709 | /// <param name="address"></param>
|
---|
710 | /// <returns></returns>
|
---|
711 | public IExcelConditionalFormattingContainsErrors AddContainsErrors(
|
---|
712 | ExcelAddress address)
|
---|
713 | {
|
---|
714 | return (IExcelConditionalFormattingContainsErrors)AddRule(
|
---|
715 | eExcelConditionalFormattingRuleType.ContainsErrors,
|
---|
716 | address);
|
---|
717 | }
|
---|
718 |
|
---|
719 | /// <summary>
|
---|
720 | /// Add ContainsText Rule
|
---|
721 | /// </summary>
|
---|
722 | /// <param name="address"></param>
|
---|
723 | /// <returns></returns>
|
---|
724 | public IExcelConditionalFormattingContainsText AddContainsText(
|
---|
725 | ExcelAddress address)
|
---|
726 | {
|
---|
727 | return (IExcelConditionalFormattingContainsText)AddRule(
|
---|
728 | eExcelConditionalFormattingRuleType.ContainsText,
|
---|
729 | address);
|
---|
730 | }
|
---|
731 |
|
---|
732 | /// <summary>
|
---|
733 | /// Add DuplicateValues Rule
|
---|
734 | /// </summary>
|
---|
735 | /// <param name="address"></param>
|
---|
736 | /// <returns></returns>
|
---|
737 | public IExcelConditionalFormattingDuplicateValues AddDuplicateValues(
|
---|
738 | ExcelAddress address)
|
---|
739 | {
|
---|
740 | return (IExcelConditionalFormattingDuplicateValues)AddRule(
|
---|
741 | eExcelConditionalFormattingRuleType.DuplicateValues,
|
---|
742 | address);
|
---|
743 | }
|
---|
744 |
|
---|
745 | /// <summary>
|
---|
746 | /// Add EndsWith Rule
|
---|
747 | /// </summary>
|
---|
748 | /// <param name="address"></param>
|
---|
749 | /// <returns></returns>
|
---|
750 | public IExcelConditionalFormattingEndsWith AddEndsWith(
|
---|
751 | ExcelAddress address)
|
---|
752 | {
|
---|
753 | return (IExcelConditionalFormattingEndsWith)AddRule(
|
---|
754 | eExcelConditionalFormattingRuleType.EndsWith,
|
---|
755 | address);
|
---|
756 | }
|
---|
757 |
|
---|
758 | /// <summary>
|
---|
759 | /// Add Equal Rule
|
---|
760 | /// </summary>
|
---|
761 | /// <param name="address"></param>
|
---|
762 | /// <returns></returns>
|
---|
763 | public IExcelConditionalFormattingEqual AddEqual(
|
---|
764 | ExcelAddress address)
|
---|
765 | {
|
---|
766 | return (IExcelConditionalFormattingEqual)AddRule(
|
---|
767 | eExcelConditionalFormattingRuleType.Equal,
|
---|
768 | address);
|
---|
769 | }
|
---|
770 |
|
---|
771 | /// <summary>
|
---|
772 | /// Add Expression Rule
|
---|
773 | /// </summary>
|
---|
774 | /// <param name="address"></param>
|
---|
775 | /// <returns></returns>
|
---|
776 | public IExcelConditionalFormattingExpression AddExpression(
|
---|
777 | ExcelAddress address)
|
---|
778 | {
|
---|
779 | return (IExcelConditionalFormattingExpression)AddRule(
|
---|
780 | eExcelConditionalFormattingRuleType.Expression,
|
---|
781 | address);
|
---|
782 | }
|
---|
783 |
|
---|
784 | /// <summary>
|
---|
785 | /// Add GreaterThan Rule
|
---|
786 | /// </summary>
|
---|
787 | /// <param name="address"></param>
|
---|
788 | /// <returns></returns>
|
---|
789 | public IExcelConditionalFormattingGreaterThan AddGreaterThan(
|
---|
790 | ExcelAddress address)
|
---|
791 | {
|
---|
792 | return (IExcelConditionalFormattingGreaterThan)AddRule(
|
---|
793 | eExcelConditionalFormattingRuleType.GreaterThan,
|
---|
794 | address);
|
---|
795 | }
|
---|
796 |
|
---|
797 | /// <summary>
|
---|
798 | /// Add GreaterThanOrEqual Rule
|
---|
799 | /// </summary>
|
---|
800 | /// <param name="address"></param>
|
---|
801 | /// <returns></returns>
|
---|
802 | public IExcelConditionalFormattingGreaterThanOrEqual AddGreaterThanOrEqual(
|
---|
803 | ExcelAddress address)
|
---|
804 | {
|
---|
805 | return (IExcelConditionalFormattingGreaterThanOrEqual)AddRule(
|
---|
806 | eExcelConditionalFormattingRuleType.GreaterThanOrEqual,
|
---|
807 | address);
|
---|
808 | }
|
---|
809 |
|
---|
810 | /// <summary>
|
---|
811 | /// Add LessThan Rule
|
---|
812 | /// </summary>
|
---|
813 | /// <param name="address"></param>
|
---|
814 | /// <returns></returns>
|
---|
815 | public IExcelConditionalFormattingLessThan AddLessThan(
|
---|
816 | ExcelAddress address)
|
---|
817 | {
|
---|
818 | return (IExcelConditionalFormattingLessThan)AddRule(
|
---|
819 | eExcelConditionalFormattingRuleType.LessThan,
|
---|
820 | address);
|
---|
821 | }
|
---|
822 |
|
---|
823 | /// <summary>
|
---|
824 | /// Add LessThanOrEqual Rule
|
---|
825 | /// </summary>
|
---|
826 | /// <param name="address"></param>
|
---|
827 | /// <returns></returns>
|
---|
828 | public IExcelConditionalFormattingLessThanOrEqual AddLessThanOrEqual(
|
---|
829 | ExcelAddress address)
|
---|
830 | {
|
---|
831 | return (IExcelConditionalFormattingLessThanOrEqual)AddRule(
|
---|
832 | eExcelConditionalFormattingRuleType.LessThanOrEqual,
|
---|
833 | address);
|
---|
834 | }
|
---|
835 |
|
---|
836 | /// <summary>
|
---|
837 | /// Add NotBetween Rule
|
---|
838 | /// </summary>
|
---|
839 | /// <param name="address"></param>
|
---|
840 | /// <returns></returns>
|
---|
841 | public IExcelConditionalFormattingNotBetween AddNotBetween(
|
---|
842 | ExcelAddress address)
|
---|
843 | {
|
---|
844 | return (IExcelConditionalFormattingNotBetween)AddRule(
|
---|
845 | eExcelConditionalFormattingRuleType.NotBetween,
|
---|
846 | address);
|
---|
847 | }
|
---|
848 |
|
---|
849 | /// <summary>
|
---|
850 | /// Add NotContainsBlanks Rule
|
---|
851 | /// </summary>
|
---|
852 | /// <param name="address"></param>
|
---|
853 | /// <returns></returns>
|
---|
854 | public IExcelConditionalFormattingNotContainsBlanks AddNotContainsBlanks(
|
---|
855 | ExcelAddress address)
|
---|
856 | {
|
---|
857 | return (IExcelConditionalFormattingNotContainsBlanks)AddRule(
|
---|
858 | eExcelConditionalFormattingRuleType.NotContainsBlanks,
|
---|
859 | address);
|
---|
860 | }
|
---|
861 |
|
---|
862 | /// <summary>
|
---|
863 | /// Add NotContainsErrors Rule
|
---|
864 | /// </summary>
|
---|
865 | /// <param name="address"></param>
|
---|
866 | /// <returns></returns>
|
---|
867 | public IExcelConditionalFormattingNotContainsErrors AddNotContainsErrors(
|
---|
868 | ExcelAddress address)
|
---|
869 | {
|
---|
870 | return (IExcelConditionalFormattingNotContainsErrors)AddRule(
|
---|
871 | eExcelConditionalFormattingRuleType.NotContainsErrors,
|
---|
872 | address);
|
---|
873 | }
|
---|
874 |
|
---|
875 | /// <summary>
|
---|
876 | /// Add NotContainsText Rule
|
---|
877 | /// </summary>
|
---|
878 | /// <param name="address"></param>
|
---|
879 | /// <returns></returns>
|
---|
880 | public IExcelConditionalFormattingNotContainsText AddNotContainsText(
|
---|
881 | ExcelAddress address)
|
---|
882 | {
|
---|
883 | return (IExcelConditionalFormattingNotContainsText)AddRule(
|
---|
884 | eExcelConditionalFormattingRuleType.NotContainsText,
|
---|
885 | address);
|
---|
886 | }
|
---|
887 |
|
---|
888 | /// <summary>
|
---|
889 | /// Add NotEqual Rule
|
---|
890 | /// </summary>
|
---|
891 | /// <param name="address"></param>
|
---|
892 | /// <returns></returns>
|
---|
893 | public IExcelConditionalFormattingNotEqual AddNotEqual(
|
---|
894 | ExcelAddress address)
|
---|
895 | {
|
---|
896 | return (IExcelConditionalFormattingNotEqual)AddRule(
|
---|
897 | eExcelConditionalFormattingRuleType.NotEqual,
|
---|
898 | address);
|
---|
899 | }
|
---|
900 |
|
---|
901 | /// <summary>
|
---|
902 | /// Add Unique Rule
|
---|
903 | /// </summary>
|
---|
904 | /// <param name="address"></param>
|
---|
905 | /// <returns></returns>
|
---|
906 | public IExcelConditionalFormattingUniqueValues AddUniqueValues(
|
---|
907 | ExcelAddress address)
|
---|
908 | {
|
---|
909 | return (IExcelConditionalFormattingUniqueValues)AddRule(
|
---|
910 | eExcelConditionalFormattingRuleType.UniqueValues,
|
---|
911 | address);
|
---|
912 | }
|
---|
913 |
|
---|
914 | /// <summary>
|
---|
915 | /// Add ThreeColorScale Rule
|
---|
916 | /// </summary>
|
---|
917 | /// <param name="address"></param>
|
---|
918 | /// <returns></returns>
|
---|
919 | public IExcelConditionalFormattingThreeColorScale AddThreeColorScale(
|
---|
920 | ExcelAddress address)
|
---|
921 | {
|
---|
922 | return (IExcelConditionalFormattingThreeColorScale)AddRule(
|
---|
923 | eExcelConditionalFormattingRuleType.ThreeColorScale,
|
---|
924 | address);
|
---|
925 | }
|
---|
926 |
|
---|
927 | /// <summary>
|
---|
928 | /// Add TwoColorScale Rule
|
---|
929 | /// </summary>
|
---|
930 | /// <param name="address"></param>
|
---|
931 | /// <returns></returns>
|
---|
932 | public IExcelConditionalFormattingTwoColorScale AddTwoColorScale(
|
---|
933 | ExcelAddress address)
|
---|
934 | {
|
---|
935 | return (IExcelConditionalFormattingTwoColorScale)AddRule(
|
---|
936 | eExcelConditionalFormattingRuleType.TwoColorScale,
|
---|
937 | address);
|
---|
938 | }
|
---|
939 |
|
---|
940 | /// <summary>
|
---|
941 | /// Add ThreeIconSet Rule
|
---|
942 | /// </summary>
|
---|
943 | /// <param name="Address">The address</param>
|
---|
944 | /// <param name="IconSet">Type of iconset</param>
|
---|
945 | /// <returns></returns>
|
---|
946 | public IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType> AddThreeIconSet(ExcelAddress Address, eExcelconditionalFormatting3IconsSetType IconSet)
|
---|
947 | {
|
---|
948 | var icon = (IExcelConditionalFormattingThreeIconSet<eExcelconditionalFormatting3IconsSetType>)AddRule(
|
---|
949 | eExcelConditionalFormattingRuleType.ThreeIconSet,
|
---|
950 | Address);
|
---|
951 | icon.IconSet = IconSet;
|
---|
952 | return icon;
|
---|
953 | }
|
---|
954 | /// <summary>
|
---|
955 | /// Adds a FourIconSet rule
|
---|
956 | /// </summary>
|
---|
957 | /// <param name="Address"></param>
|
---|
958 | /// <param name="IconSet"></param>
|
---|
959 | /// <returns></returns>
|
---|
960 | public IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType> AddFourIconSet(ExcelAddress Address, eExcelconditionalFormatting4IconsSetType IconSet)
|
---|
961 | {
|
---|
962 | var icon = (IExcelConditionalFormattingFourIconSet<eExcelconditionalFormatting4IconsSetType>)AddRule(
|
---|
963 | eExcelConditionalFormattingRuleType.FourIconSet,
|
---|
964 | Address);
|
---|
965 | icon.IconSet = IconSet;
|
---|
966 | return icon;
|
---|
967 | }
|
---|
968 | /// <summary>
|
---|
969 | /// Adds a FiveIconSet rule
|
---|
970 | /// </summary>
|
---|
971 | /// <param name="Address"></param>
|
---|
972 | /// <param name="IconSet"></param>
|
---|
973 | /// <returns></returns>
|
---|
974 | public IExcelConditionalFormattingFiveIconSet AddFiveIconSet(ExcelAddress Address, eExcelconditionalFormatting5IconsSetType IconSet)
|
---|
975 | {
|
---|
976 | var icon = (IExcelConditionalFormattingFiveIconSet)AddRule(
|
---|
977 | eExcelConditionalFormattingRuleType.FiveIconSet,
|
---|
978 | Address);
|
---|
979 | icon.IconSet = IconSet;
|
---|
980 | return icon;
|
---|
981 | }
|
---|
982 | /// <summary>
|
---|
983 | /// Adds a databar rule
|
---|
984 | /// </summary>
|
---|
985 | /// <param name="Address"></param>
|
---|
986 | /// <param name="color"></param>
|
---|
987 | /// <returns></returns>
|
---|
988 | public IExcelConditionalFormattingDataBarGroup AddDatabar(ExcelAddress Address, Color color)
|
---|
989 | {
|
---|
990 | var dataBar = (IExcelConditionalFormattingDataBarGroup)AddRule(
|
---|
991 | eExcelConditionalFormattingRuleType.DataBar,
|
---|
992 | Address);
|
---|
993 | dataBar.Color=color;
|
---|
994 | return dataBar;
|
---|
995 | }
|
---|
996 | #endregion Conditional Formatting Rules
|
---|
997 |
|
---|
998 | }
|
---|
999 | } |
---|