Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Style/XmlAccess/ExcelBorderItemXml.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: 5.4 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 * Jan Källman                    Initial Release           2009-10-01
30 * Jan Källman    License changed GPL-->LGPL 2011-12-16
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Globalization;
35using System.Text;
36using System.Xml;
37using OfficeOpenXml.Style;
38namespace OfficeOpenXml.Style.XmlAccess
39{
40    /// <summary>
41    /// Xml access class for border items
42    /// </summary>
43    public sealed class ExcelBorderItemXml : StyleXmlHelper
44    {
45        internal ExcelBorderItemXml(XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
46        {
47            _borderStyle=ExcelBorderStyle.None;
48            _color = new ExcelColorXml(NameSpaceManager);
49        }
50        internal ExcelBorderItemXml(XmlNamespaceManager nsm, XmlNode topNode) :
51            base(nsm, topNode)
52        {
53            if (topNode != null)
54            {
55                _borderStyle = GetBorderStyle(GetXmlNodeString("@style"));
56                _color = new ExcelColorXml(nsm, topNode.SelectSingleNode(_colorPath, nsm));
57                Exists = true;
58            }
59            else
60            {
61                Exists = false;
62            }
63        }
64
65        private ExcelBorderStyle GetBorderStyle(string style)
66        {
67            if(style=="") return ExcelBorderStyle.None;
68            string sInStyle = style.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) + style.Substring(1, style.Length - 1);
69            try
70            {
71                return (ExcelBorderStyle)Enum.Parse(typeof(ExcelBorderStyle), sInStyle);
72            }
73            catch
74            {
75                return ExcelBorderStyle.None;
76            }
77
78        }
79        ExcelBorderStyle _borderStyle = ExcelBorderStyle.None;
80        /// <summary>
81        /// Cell Border style
82        /// </summary>
83        public ExcelBorderStyle Style
84        {
85            get
86            {
87                return _borderStyle;
88            }
89            set
90            {
91                _borderStyle = value;
92                Exists = true;
93            }
94        }
95        ExcelColorXml _color = null;
96        const string _colorPath = "d:color";
97        /// <summary>
98        /// Border style
99        /// </summary>
100        public ExcelColorXml Color
101        {
102            get
103            {
104                return _color;
105            }
106            internal set
107            {
108                _color = value;
109            }
110        }
111        internal override string Id
112        {
113            get
114            {
115                if (Exists)
116                {
117                    return Style + Color.Id;
118                }
119                else
120                {
121                    return "None";
122                }
123            }
124        }
125
126        internal ExcelBorderItemXml Copy()
127        {
128            ExcelBorderItemXml borderItem = new ExcelBorderItemXml(NameSpaceManager);
129            borderItem.Style = _borderStyle;
130            borderItem.Color = _color.Copy();
131            return borderItem;
132        }
133
134        internal override XmlNode CreateXmlNode(XmlNode topNode)
135        {
136            TopNode = topNode;
137
138            if (Style != ExcelBorderStyle.None)
139            {
140                SetXmlNodeString("@style", SetBorderString(Style));
141                if (Color.Exists)
142                {
143                    CreateNode(_colorPath);
144                    topNode.AppendChild(Color.CreateXmlNode(TopNode.SelectSingleNode(_colorPath,NameSpaceManager)));
145                }
146            }
147            return TopNode;
148        }
149
150        private string SetBorderString(ExcelBorderStyle Style)
151        {
152            string newName=Enum.GetName(typeof(ExcelBorderStyle), Style);
153            return newName.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + newName.Substring(1, newName.Length - 1);
154        }
155        public bool Exists { get; private set; }
156    }
157}
Note: See TracBrowser for help on using the repository browser.