Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2989_MovingPeaksBenchmark/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Style/ExcelBorder.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: 7.7 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.Text;
35using OfficeOpenXml.Style.XmlAccess;
36
37namespace OfficeOpenXml.Style
38{
39    /// <summary>
40    /// Cell Border style
41    /// </summary>
42    public sealed class Border : StyleBase
43    {
44        internal Border(ExcelStyles styles, OfficeOpenXml.XmlHelper.ChangedEventHandler ChangedEvent, int PositionID, string address, int index) :
45            base(styles, ChangedEvent, PositionID, address)
46      {
47            Index = index;
48        }
49        /// <summary>
50        /// Left border style
51        /// </summary>
52        public ExcelBorderItem Left
53        {
54            get
55            {
56                return new ExcelBorderItem(_styles, _ChangedEvent, _positionID, _address, eStyleClass.BorderLeft, this);
57            }
58        }
59        /// <summary>
60        /// Right border style
61        /// </summary>
62        public ExcelBorderItem Right
63        {
64            get
65            {
66                return new ExcelBorderItem(_styles, _ChangedEvent, _positionID, _address, eStyleClass.BorderRight, this);
67            }
68        }
69        /// <summary>
70        /// Top border style
71        /// </summary>
72        public ExcelBorderItem Top
73        {
74            get
75            {
76                return new ExcelBorderItem(_styles, _ChangedEvent, _positionID, _address, eStyleClass.BorderTop, this);
77            }
78        }
79        /// <summary>
80        /// Bottom border style
81        /// </summary>
82        public ExcelBorderItem Bottom
83        {
84            get
85            {
86                return new ExcelBorderItem(_styles, _ChangedEvent, _positionID, _address, eStyleClass.BorderBottom, this);
87            }
88        }
89        /// <summary>
90        /// 0Diagonal border style
91        /// </summary>
92        public ExcelBorderItem Diagonal
93        {
94            get
95            {
96                return new ExcelBorderItem(_styles, _ChangedEvent, _positionID, _address, eStyleClass.BorderDiagonal, this);
97            }
98        }
99        /// <summary>
100        /// A diagonal from the bottom left to top right of the cell
101        /// </summary>
102        public bool DiagonalUp
103        {
104            get
105            {
106                if (Index >=0)
107                {
108                    return _styles.Borders[Index].DiagonalUp;
109                }
110                else
111                {
112                    return false;
113                }
114            }
115            set
116            {
117                _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Border, eStyleProperty.BorderDiagonalUp, value, _positionID, _address));
118            }
119        }
120        /// <summary>
121        /// A diagonal from the top left to bottom right of the cell
122        /// </summary>
123        public bool DiagonalDown
124        {
125            get
126            {
127                if (Index >= 0)
128                {
129                    return _styles.Borders[Index].DiagonalDown;
130                }
131                else
132                {
133                    return false;
134                }
135            }
136            set
137            {
138                _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.Border, eStyleProperty.BorderDiagonalDown, value, _positionID, _address));
139            }
140        }
141        internal override string Id
142        {
143            get { return Top.Id + Bottom.Id +Left.Id + Right.Id + Diagonal.Id + DiagonalUp + DiagonalDown; }
144        }
145        /// <summary>
146        /// Set the border style around the range.
147        /// </summary>
148        /// <param name="Style">The border style</param>
149        public void BorderAround(ExcelBorderStyle Style)
150        {
151            var addr = new ExcelAddress(_address);
152            SetBorderAroundStyle(Style, addr);
153        }
154        /// <summary>
155        /// Set the border style around the range.
156        /// </summary>
157        /// <param name="Style">The border style</param>
158        /// <param name="Color">The color of the border</param>
159        public void BorderAround(ExcelBorderStyle Style, System.Drawing.Color Color)
160        {           
161            var addr=new ExcelAddress(_address);
162            SetBorderAroundStyle(Style, addr);
163
164            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderTop, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address));
165            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderBottom, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address));
166            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderLeft, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address));
167            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderRight, eStyleProperty.Color, Color.ToArgb().ToString("X"), _positionID, new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address));
168        }
169
170        private void SetBorderAroundStyle(ExcelBorderStyle Style, ExcelAddress addr)
171        {
172            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderTop, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._fromRow, addr._toCol).Address));
173            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderBottom, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._toRow, addr._fromCol, addr._toRow, addr._toCol).Address));
174            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderLeft, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._fromCol, addr._toRow, addr._fromCol).Address));
175            _ChangedEvent(this, new StyleChangeEventArgs(eStyleClass.BorderRight, eStyleProperty.Style, Style, _positionID, new ExcelAddress(addr._fromRow, addr._toCol, addr._toRow, addr._toCol).Address));
176        }
177    }
178}
Note: See TracBrowser for help on using the repository browser.