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 Adaption 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 |
|
---|
37 | namespace OfficeOpenXml.ConditionalFormatting
|
---|
38 | {
|
---|
39 | /// <summary>
|
---|
40 | /// Functions related to the <see cref="ExcelConditionalFormattingColorScaleValue"/>
|
---|
41 | /// </summary>
|
---|
42 | internal static class ExcelConditionalFormattingValueObjectType
|
---|
43 | {
|
---|
44 | /// <summary>
|
---|
45 | /// Get the sequencial order of a cfvo/color by its position.
|
---|
46 | /// </summary>
|
---|
47 | /// <param name="position"></param>
|
---|
48 | /// <param name="ruleType"></param>
|
---|
49 | /// <returns>1, 2 or 3</returns>
|
---|
50 | internal static int GetOrderByPosition(
|
---|
51 | eExcelConditionalFormattingValueObjectPosition position,
|
---|
52 | eExcelConditionalFormattingRuleType ruleType)
|
---|
53 | {
|
---|
54 | switch (position)
|
---|
55 | {
|
---|
56 | case eExcelConditionalFormattingValueObjectPosition.Low:
|
---|
57 | return 1;
|
---|
58 |
|
---|
59 | case eExcelConditionalFormattingValueObjectPosition.Middle:
|
---|
60 | return 2;
|
---|
61 |
|
---|
62 | case eExcelConditionalFormattingValueObjectPosition.High:
|
---|
63 | // Check if the rule type is TwoColorScale.
|
---|
64 | if (ruleType == eExcelConditionalFormattingRuleType.TwoColorScale)
|
---|
65 | {
|
---|
66 | // There are only "Low" and "High". So "High" is the second
|
---|
67 | return 2;
|
---|
68 | }
|
---|
69 |
|
---|
70 | // There are "Low", "Middle" and "High". So "High" is the third
|
---|
71 | return 3;
|
---|
72 | }
|
---|
73 |
|
---|
74 | return 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /// <summary>
|
---|
78 | /// Get the CFVO type by its @type attribute
|
---|
79 | /// </summary>
|
---|
80 | /// <param name="attribute"></param>
|
---|
81 | /// <returns></returns>
|
---|
82 | public static eExcelConditionalFormattingValueObjectType GetTypeByAttrbiute(
|
---|
83 | string attribute)
|
---|
84 | {
|
---|
85 | switch (attribute)
|
---|
86 | {
|
---|
87 | case ExcelConditionalFormattingConstants.CfvoType.Min:
|
---|
88 | return eExcelConditionalFormattingValueObjectType.Min;
|
---|
89 |
|
---|
90 | case ExcelConditionalFormattingConstants.CfvoType.Max:
|
---|
91 | return eExcelConditionalFormattingValueObjectType.Max;
|
---|
92 |
|
---|
93 | case ExcelConditionalFormattingConstants.CfvoType.Num:
|
---|
94 | return eExcelConditionalFormattingValueObjectType.Num;
|
---|
95 |
|
---|
96 | case ExcelConditionalFormattingConstants.CfvoType.Formula:
|
---|
97 | return eExcelConditionalFormattingValueObjectType.Formula;
|
---|
98 |
|
---|
99 | case ExcelConditionalFormattingConstants.CfvoType.Percent:
|
---|
100 | return eExcelConditionalFormattingValueObjectType.Percent;
|
---|
101 |
|
---|
102 | case ExcelConditionalFormattingConstants.CfvoType.Percentile:
|
---|
103 | return eExcelConditionalFormattingValueObjectType.Percentile;
|
---|
104 | }
|
---|
105 |
|
---|
106 | throw new Exception(
|
---|
107 | ExcelConditionalFormattingConstants.Errors.UnexistentCfvoTypeAttribute);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /// <summary>
|
---|
111 | ///
|
---|
112 | /// </summary>
|
---|
113 | /// <param name="position"></param>
|
---|
114 | ///<param name="ruleType"></param>
|
---|
115 | /// <param name="topNode"></param>
|
---|
116 | /// <param name="nameSpaceManager"></param>
|
---|
117 | /// <returns></returns>
|
---|
118 | public static XmlNode GetCfvoNodeByPosition(
|
---|
119 | eExcelConditionalFormattingValueObjectPosition position,
|
---|
120 | eExcelConditionalFormattingRuleType ruleType,
|
---|
121 | XmlNode topNode,
|
---|
122 | XmlNamespaceManager nameSpaceManager)
|
---|
123 | {
|
---|
124 | // Get the corresponding <cfvo> node (by the position)
|
---|
125 | var node = topNode.SelectSingleNode(
|
---|
126 | string.Format(
|
---|
127 | "{0}[position()={1}]",
|
---|
128 | // {0}
|
---|
129 | ExcelConditionalFormattingConstants.Paths.Cfvo,
|
---|
130 | // {1}
|
---|
131 | ExcelConditionalFormattingValueObjectType.GetOrderByPosition(position, ruleType)),
|
---|
132 | nameSpaceManager);
|
---|
133 |
|
---|
134 | if (node == null)
|
---|
135 | {
|
---|
136 | throw new Exception(
|
---|
137 | ExcelConditionalFormattingConstants.Errors.MissingCfvoNode);
|
---|
138 | }
|
---|
139 |
|
---|
140 | return node;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /// <summary>
|
---|
144 | ///
|
---|
145 | /// </summary>
|
---|
146 | /// <param name="type"></param>
|
---|
147 | /// <returns></returns>
|
---|
148 | public static string GetAttributeByType(
|
---|
149 | eExcelConditionalFormattingValueObjectType type)
|
---|
150 | {
|
---|
151 | switch (type)
|
---|
152 | {
|
---|
153 | case eExcelConditionalFormattingValueObjectType.Min:
|
---|
154 | return ExcelConditionalFormattingConstants.CfvoType.Min;
|
---|
155 |
|
---|
156 | case eExcelConditionalFormattingValueObjectType.Max:
|
---|
157 | return ExcelConditionalFormattingConstants.CfvoType.Max;
|
---|
158 |
|
---|
159 | case eExcelConditionalFormattingValueObjectType.Num:
|
---|
160 | return ExcelConditionalFormattingConstants.CfvoType.Num;
|
---|
161 |
|
---|
162 | case eExcelConditionalFormattingValueObjectType.Formula:
|
---|
163 | return ExcelConditionalFormattingConstants.CfvoType.Formula;
|
---|
164 |
|
---|
165 | case eExcelConditionalFormattingValueObjectType.Percent:
|
---|
166 | return ExcelConditionalFormattingConstants.CfvoType.Percent;
|
---|
167 |
|
---|
168 | case eExcelConditionalFormattingValueObjectType.Percentile:
|
---|
169 | return ExcelConditionalFormattingConstants.CfvoType.Percentile;
|
---|
170 | }
|
---|
171 |
|
---|
172 | return string.Empty;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /// <summary>
|
---|
176 | /// Get the cfvo (§18.3.1.11) node parent by the rule type. Can be any of the following:
|
---|
177 | /// "colorScale" (§18.3.1.16); "dataBar" (§18.3.1.28); "iconSet" (§18.3.1.49)
|
---|
178 | /// </summary>
|
---|
179 | /// <param name="ruleType"></param>
|
---|
180 | /// <returns></returns>
|
---|
181 | public static string GetParentPathByRuleType(
|
---|
182 | eExcelConditionalFormattingRuleType ruleType)
|
---|
183 | {
|
---|
184 | switch (ruleType)
|
---|
185 | {
|
---|
186 | case eExcelConditionalFormattingRuleType.TwoColorScale:
|
---|
187 | case eExcelConditionalFormattingRuleType.ThreeColorScale:
|
---|
188 | return ExcelConditionalFormattingConstants.Paths.ColorScale;
|
---|
189 |
|
---|
190 | case eExcelConditionalFormattingRuleType.ThreeIconSet:
|
---|
191 | case eExcelConditionalFormattingRuleType.FourIconSet:
|
---|
192 | case eExcelConditionalFormattingRuleType.FiveIconSet:
|
---|
193 | return ExcelConditionalFormattingConstants.Paths.IconSet;
|
---|
194 |
|
---|
195 | case eExcelConditionalFormattingRuleType.DataBar:
|
---|
196 | return ExcelConditionalFormattingConstants.Paths.DataBar;
|
---|
197 | }
|
---|
198 |
|
---|
199 | return string.Empty;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /// <summary>
|
---|
203 | ///
|
---|
204 | /// </summary>
|
---|
205 | /// <param name="nodeType"></param>
|
---|
206 | /// <returns></returns>
|
---|
207 | public static string GetNodePathByNodeType(
|
---|
208 | eExcelConditionalFormattingValueObjectNodeType nodeType)
|
---|
209 | {
|
---|
210 | switch(nodeType)
|
---|
211 | {
|
---|
212 | case eExcelConditionalFormattingValueObjectNodeType.Cfvo:
|
---|
213 | return ExcelConditionalFormattingConstants.Paths.Cfvo;
|
---|
214 |
|
---|
215 | case eExcelConditionalFormattingValueObjectNodeType.Color:
|
---|
216 | return ExcelConditionalFormattingConstants.Paths.Color;
|
---|
217 | }
|
---|
218 |
|
---|
219 | return string.Empty;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | } |
---|