Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/ExcelRange.cs @ 11733

Last change on this file since 11733 was 9580, checked in by sforsten, 12 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.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 * 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        /// <summary>
93        /// Access a single cell
94        /// </summary>
95        /// <param name="Row">The row</param>
96        /// <param name="Col">The column</param>
97        /// <returns>A range object</returns>
98        public ExcelRange this[int Row, int Col]
99        {
100            get
101            {
102                ValidateRowCol(Row, Col);
103
104                _fromCol = Col;
105                _fromRow = Row;
106                _toCol = Col;
107                _toRow = Row;
108                base.Address = GetAddress(_fromRow, _fromCol);
109                return this;
110            }
111        }
112        /// <summary>
113        /// Access a range of cells
114        /// </summary>
115        /// <param name="FromRow">Start row</param>
116        /// <param name="FromCol">Start column</param>
117        /// <param name="ToRow">End Row</param>
118        /// <param name="ToCol">End Column</param>
119        /// <returns></returns>
120        public ExcelRange this[int FromRow, int FromCol, int ToRow, int ToCol]
121        {
122            get
123            {
124                ValidateRowCol(FromRow, FromCol);
125                ValidateRowCol(ToRow, ToCol);
126
127                _fromCol = FromCol;
128                _fromRow = FromRow;
129                _toCol = ToCol;
130                _toRow = ToRow;
131                base.Address = GetAddress(_fromRow, _fromCol, _toRow, _toCol);
132                return this;
133            }
134        }
135        #endregion
136        private static void ValidateRowCol(int Row, int Col)
137        {
138            if (Row < 1 || Row > ExcelPackage.MaxRows)
139            {
140                throw (new ArgumentException("Row out of range"));
141            }
142            if (Col < 1 || Col > ExcelPackage.MaxColumns)
143            {
144                throw (new ArgumentException("Column out of range"));
145            }
146        }
147
148    }
149}
Note: See TracBrowser for help on using the repository browser.