xlnt - community edition
range_reference.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2024-2025 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  bool whole_row() const;
82 
86  bool whole_column() const;
87 
91  std::size_t width() const;
92 
96  std::size_t height() const;
97 
101  cell_reference top_left() const;
102 
106  cell_reference top_right() const;
107 
111  cell_reference bottom_left() const;
112 
116  cell_reference bottom_right() const;
117 
122  range_reference make_offset(int column_offset, int row_offset) const;
123 
127  std::string to_string() const;
128 
132  bool contains(const cell_reference &ref) const;
133 
137  bool operator==(const range_reference &comparand) const;
138 
143  bool operator==(const std::string &reference_string) const;
144 
149  bool operator==(const char *reference_string) const;
150 
154  bool operator!=(const range_reference &comparand) const;
155 
160  bool operator!=(const std::string &reference_string) const;
161 
166  bool operator!=(const char *reference_string) const;
167 
168 private:
172  cell_reference top_left_;
173 
177  cell_reference bottom_right_;
178 };
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 
193 XLNT_API bool operator!=(const std::string &reference_string, const range_reference &ref);
194 
198 XLNT_API bool operator!=(const char *reference_string, const range_reference &ref);
199 
200 } // namespace xlnt
std::uint32_t row_t
All rows should be referred to by an instance of this type.
Definition: index_types.hpp:40
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:36
bool operator!=(std::nullptr_t, const cell &cell)
Returns true if this cell is initialized.
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:59
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:47
A range_reference describes a rectangular area of a worksheet with positive width and height defined ...
Definition: range_reference.hpp:36