xlnt
range_reference.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2024 xlnt-community
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <xlnt/xlnt_config.hpp>
28 #include <xlnt/cell/cell_reference.hpp>
29 
30 namespace xlnt {
31 
36 class XLNT_API range_reference
37 {
38 public:
42  static range_reference make_absolute(const range_reference &relative_reference);
43 
48 
53  explicit range_reference(const std::string &range_string);
54 
59  explicit range_reference(const char *range_string);
60 
65  range_reference(const cell_reference &start, const cell_reference &end);
66 
70  range_reference(column_t column_index_start, row_t row_index_start,
71  column_t column_index_end, row_t row_index_end);
72 
76  bool is_single_cell() const;
77 
81  std::size_t width() const;
82 
86  std::size_t height() const;
87 
91  cell_reference top_left() const;
92 
96  cell_reference top_right() const;
97 
101  cell_reference bottom_left() const;
102 
106  cell_reference bottom_right() const;
107 
112  range_reference make_offset(int column_offset, int row_offset) const;
113 
117  std::string to_string() const;
118 
122  bool contains(const cell_reference &ref) const;
123 
127  bool operator==(const range_reference &comparand) const;
128 
133  bool operator==(const std::string &reference_string) const;
134 
139  bool operator==(const char *reference_string) const;
140 
144  bool operator!=(const range_reference &comparand) const;
145 
150  bool operator!=(const std::string &reference_string) const;
151 
156  bool operator!=(const char *reference_string) const;
157 
158 private:
162  cell_reference top_left_;
163 
167  cell_reference bottom_right_;
168 };
169 
173 XLNT_API bool operator==(const std::string &reference_string, const range_reference &ref);
174 
178 XLNT_API bool operator==(const char *reference_string, const range_reference &ref);
179 
183 XLNT_API bool operator!=(const std::string &reference_string, const range_reference &ref);
184 
188 XLNT_API bool operator!=(const char *reference_string, const range_reference &ref);
189 
190 } // namespace xlnt
std::uint32_t row_t
All rows should be referred to by an instance of this type.
Definition: index_types.hpp:41
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
An object used to refer to a cell. References have two parts, the column and the row. In Excel, the reference string A1 refers to the top-left-most cell. A cell_reference can be initialized from a string of this form or a 1-indexed ordered pair of the form column, row.
Definition: cell_reference.hpp:60
Columns can be referred to as a string A,B,...Z,AA,AB,..,ZZ,AAA,...,ZZZ or as a 1-indexed index...
Definition: index_types.hpp:48
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.
A range_reference describes a rectangular area of a worksheet with positive width and height defined ...
Definition: range_reference.hpp:36