Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3044_variableScaling/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/ExcelRange.cs @ 18242

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

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 5.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-27
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using OfficeOpenXml.Style;
36using System.Data;
37namespace OfficeOpenXml
38{
39    /// <summary>
40    /// A range of cells.
41    /// </summary>
42    public class ExcelRange : ExcelRangeBase
43    {
44        #region "Constructors"
45        internal ExcelRange(ExcelWorksheet sheet) :
46            base(sheet)
47        {
48
49        }
50        internal ExcelRange(ExcelWorksheet sheet, string address)
51            : base(sheet, address)
52        {
53
54        }
55        internal ExcelRange(ExcelWorksheet sheet, int fromRow, int fromCol, int toRow, int toCol)
56            : base(sheet)
57        {
58            _fromRow = fromRow;
59            _fromCol = fromCol;
60            _toRow = toRow;
61            _toCol = toCol;
62        }
63        #endregion
64        #region "Indexers"
65        /// <summary>
66        /// Access the range using an address
67        /// </summary>
68        /// <param name="Address">The address</param>
69        /// <returns>A range object</returns>
70        public ExcelRange this[string Address]
71        {
72            get
73            {
74                if (_worksheet.Names.ContainsKey(Address))
75                {
76                    if (_worksheet.Names[Address].IsName)
77                    {
78                        return null;
79                    }
80                    else
81                    {
82                        base.Address = _worksheet.Names[Address].Address;
83                    }
84                }
85                else
86                {
87                    base.Address = Address;
88                }
89                return this;
90            }
91        }
92
93        private ExcelRange GetTableAddess(ExcelWorksheet _worksheet, string address)
94        {
95            int ixStart = address.IndexOf('[');
96            if (ixStart == 0) //External Address
97            {
98                int ixEnd = address.IndexOf(']',ixStart+1);
99                if (ixStart >= 0 & ixEnd >= 0)
100                {
101                    var external = address.Substring(ixStart + 1, ixEnd - 1);
102                    //if (Worksheet.Workbook._externalReferences.Count < external)
103                    //{
104                    //foreach(var
105                    //}
106                }
107            }
108            return null;
109        }
110        /// <summary>
111        /// Access a single cell
112        /// </summary>
113        /// <param name="Row">The row</param>
114        /// <param name="Col">The column</param>
115        /// <returns>A range object</returns>
116        public ExcelRange this[int Row, int Col]
117        {
118            get
119            {
120                ValidateRowCol(Row, Col);
121
122                _fromCol = Col;
123                _fromRow = Row;
124                _toCol = Col;
125                _toRow = Row;
126                base.Address = GetAddress(_fromRow, _fromCol);
127                return this;
128            }
129        }
130        /// <summary>
131        /// Access a range of cells
132        /// </summary>
133        /// <param name="FromRow">Start row</param>
134        /// <param name="FromCol">Start column</param>
135        /// <param name="ToRow">End Row</param>
136        /// <param name="ToCol">End Column</param>
137        /// <returns></returns>
138        public ExcelRange this[int FromRow, int FromCol, int ToRow, int ToCol]
139        {
140            get
141            {
142                ValidateRowCol(FromRow, FromCol);
143                ValidateRowCol(ToRow, ToCol);
144
145                _fromCol = FromCol;
146                _fromRow = FromRow;
147                _toCol = ToCol;
148                _toRow = ToRow;
149                base.Address = GetAddress(_fromRow, _fromCol, _toRow, _toCol);
150                return this;
151            }
152        }
153        #endregion
154        private static void ValidateRowCol(int Row, int Col)
155        {
156            if (Row < 1 || Row > ExcelPackage.MaxRows)
157            {
158                throw (new ArgumentException("Row out of range"));
159            }
160            if (Col < 1 || Col > ExcelPackage.MaxColumns)
161            {
162                throw (new ArgumentException("Column out of range"));
163            }
164        }
165
166    }
167}
Note: See TracBrowser for help on using the repository browser.