Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/ExcelCellAddress.cs @ 15888

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

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 5.1 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 *  Starnuto Di Topo & Jan Källman  Initial Release           2010-03-14
30 * Jan Källman    License changed GPL-->LGPL 2011-12-27
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace OfficeOpenXml
37{
38    /// <summary>
39    /// A single cell address
40    /// </summary>
41    public class ExcelCellAddress
42    {
43        public ExcelCellAddress()
44            : this(1, 1)
45        {
46
47        }
48
49        private int _row;
50        private int _column;
51        private string _address;
52        /// <summary>
53        /// Initializes a new instance of the ExcelCellAddress class.
54        /// </summary>
55        /// <param name="row">The row.</param>
56        /// <param name="column">The column.</param>
57        public ExcelCellAddress(int row, int column)
58        {
59            this.Row = row;
60            this.Column = column;
61        }
62        /// <summary>
63        /// Initializes a new instance of the ExcelCellAddress class.
64        /// </summary>
65        ///<param name="address">The address</param>
66        public ExcelCellAddress(string address)
67        {
68            this.Address = address;
69        }
70        /// <summary>
71        /// Row
72        /// </summary>
73        public int Row
74        {
75            get
76            {
77                return this._row;
78            }
79            private set
80            {
81                if (value <= 0)
82                {
83                    throw new ArgumentOutOfRangeException("value", "Row cannot be less than 1.");
84                }
85                this._row = value;
86                if(_column>0)
87                    _address = ExcelCellBase.GetAddress(_row, _column);
88                else
89                    _address = "#REF!";
90            }
91        }
92        /// <summary>
93        /// Column
94        /// </summary>
95        public int Column
96        {
97            get
98            {
99                return this._column;
100            }
101            private set
102            {
103                if (value <= 0)
104                {
105                    throw new ArgumentOutOfRangeException("value", "Column cannot be less than 1.");
106                }
107                this._column = value;
108                if (_row > 0)
109                    _address = ExcelCellBase.GetAddress(_row, _column);
110                else
111                    _address = "#REF!";
112            }
113        }
114        /// <summary>
115        /// Celladdress
116        /// </summary>
117        public string Address
118        {
119            get
120            {
121                return _address;
122            }
123            internal set
124            {
125                _address = value;
126                ExcelCellBase.GetRowColFromAddress(_address, out _row, out _column);
127            }
128        }
129        /// <summary>
130        /// If the address is an invalid reference (#REF!)
131        /// </summary>
132        public bool IsRef
133        {
134            get
135            {
136                return _row <= 0;
137            }
138        }
139
140        /// <summary>
141        /// Returns the letter corresponding to the supplied 1-based column index.
142        /// </summary>
143        /// <param name="column">Index of the column (1-based)</param>
144        /// <returns>The corresponding letter, like A for 1.</returns>
145        public static string GetColumnLetter(int column)
146        {
147            if (column > ExcelPackage.MaxColumns || column < 1)
148            {
149                throw new InvalidOperationException("Invalid 1-based column index: " + column + ". Valid range is 1 to " + ExcelPackage.MaxColumns);
150            }
151            return ExcelCellBase.GetColumnLetter(column);
152        }
153    }
154}
155
Note: See TracBrowser for help on using the repository browser.