Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/ConditionalFormatting/Rules/ExcelConditionalFormattingDataBar.cs

Last change on this file was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 8.3 KB
Line 
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        Added            2012-04-03
30 *******************************************************************************/
31using System;
32using System.Collections.Generic;
33using System.Linq;
34using System.Text;
35using System.Drawing;
36using System.Xml;
37using OfficeOpenXml.ConditionalFormatting.Contracts;
38using System.Globalization;
39namespace OfficeOpenXml.ConditionalFormatting
40{
41    /// <summary>
42    /// Databar
43    /// </summary>
44    public class ExcelConditionalFormattingDataBar
45      : ExcelConditionalFormattingRule,
46        IExcelConditionalFormattingDataBarGroup
47    {
48        /****************************************************************************************/
49
50        #region Private Properties
51
52        #endregion Private Properties
53
54        /****************************************************************************************/
55
56        #region Constructors
57        /// <summary>
58        ///
59        /// </summary>
60        /// <param name="type"></param>
61        /// <param name="priority"></param>
62        /// <param name="address"></param>
63        /// <param name="worksheet"></param>
64        /// <param name="itemElementNode"></param>
65        /// <param name="namespaceManager"></param>
66        internal ExcelConditionalFormattingDataBar(
67          eExcelConditionalFormattingRuleType type,
68          ExcelAddress address,
69          int priority,
70          ExcelWorksheet worksheet,
71          XmlNode itemElementNode,
72          XmlNamespaceManager namespaceManager)
73            : base(
74              type,
75              address,
76              priority,
77              worksheet,
78              itemElementNode,
79              (namespaceManager == null) ? worksheet.NameSpaceManager : namespaceManager)
80        {
81            SchemaNodeOrder = new string[] { "cfvo", "color" };
82            //Create the <dataBar> node inside the <cfRule> node
83            if (itemElementNode!=null && itemElementNode.HasChildNodes)
84            {
85                bool high=false;
86                foreach (XmlNode node in itemElementNode.SelectNodes("d:dataBar/d:cfvo", NameSpaceManager))
87                {
88                    if (high == false)
89                    {
90                        LowValue = new ExcelConditionalFormattingIconDataBarValue(
91                                type,
92                                address,
93                                worksheet,
94                                node,
95                                namespaceManager);
96                        high = true;
97                    }
98                    else
99                    {
100                        HighValue = new ExcelConditionalFormattingIconDataBarValue(
101                                type,
102                                address,
103                                worksheet,
104                                node,
105                                namespaceManager);
106                    }
107                }
108            }
109            else
110            {
111                var iconSetNode = CreateComplexNode(
112                  Node,
113                  ExcelConditionalFormattingConstants.Paths.DataBar);
114
115                var lowNode = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
116                iconSetNode.AppendChild(lowNode);
117                LowValue = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Min,
118                        0,
119                        "",
120                        eExcelConditionalFormattingRuleType.DataBar,
121                        address,
122                        priority,
123                        worksheet,
124                        lowNode,
125                        namespaceManager);
126
127                var highNode = iconSetNode.OwnerDocument.CreateElement(ExcelConditionalFormattingConstants.Paths.Cfvo, ExcelPackage.schemaMain);
128                iconSetNode.AppendChild(highNode);
129                HighValue = new ExcelConditionalFormattingIconDataBarValue(eExcelConditionalFormattingValueObjectType.Max,
130                        0,
131                        "",
132                        eExcelConditionalFormattingRuleType.DataBar,
133                        address,
134                        priority,
135                        worksheet,
136                        highNode,
137                        namespaceManager);
138            }
139            Type = type;
140        }
141
142        /// <summary>
143        ///
144        /// </summary>
145        /// <param name="type"></param>
146        /// <param name="priority"></param>
147        /// <param name="address"></param>
148        /// <param name="worksheet"></param>
149        /// <param name="itemElementNode"></param>
150        internal ExcelConditionalFormattingDataBar(
151          eExcelConditionalFormattingRuleType type,
152          ExcelAddress address,
153          int priority,
154          ExcelWorksheet worksheet,
155          XmlNode itemElementNode)
156            : this(
157              type,
158              address,
159              priority,
160              worksheet,
161              itemElementNode,
162              null)
163        {
164        }
165
166        /// <summary>
167        ///
168        /// </summary>
169        /// <param name="type"></param>
170        /// <param name="priority"></param>
171        /// <param name="address"></param>
172        /// <param name="worksheet"></param>
173        internal ExcelConditionalFormattingDataBar(
174          eExcelConditionalFormattingRuleType type,
175          ExcelAddress address,
176          int priority,
177          ExcelWorksheet worksheet)
178            : this(
179              type,
180              address,
181              priority,
182              worksheet,
183              null,
184              null)
185        {
186        }
187        #endregion Constructors
188        private const string _showValuePath="d:dataBar/@showValue";
189        public bool ShowValue
190        {
191            get
192            {
193                return GetXmlNodeBool(_showValuePath, true);
194            }
195            set
196            {
197                SetXmlNodeBool(_showValuePath, value);
198            }
199        }
200
201
202        public ExcelConditionalFormattingIconDataBarValue LowValue
203        {
204            get;
205            internal set;
206        }
207
208        public ExcelConditionalFormattingIconDataBarValue HighValue
209        {
210            get;
211            internal set;
212        }
213
214
215        private const string _colorPath = "d:dataBar/d:color/@rgb";
216        public Color Color
217        {
218            get
219            {
220                var rgb=GetXmlNodeString(_colorPath);
221                if(!string.IsNullOrEmpty(rgb))
222                {
223                    return Color.FromArgb(int.Parse(rgb, NumberStyles.HexNumber));
224                }
225                return Color.White;
226            }
227            set
228            {
229                SetXmlNodeString(_colorPath, value.ToArgb().ToString("X"));
230            }
231        }
232    }
233}
Note: See TracBrowser for help on using the repository browser.