// Copyright (c) 2014-2021 Thomas Fussell // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace xlnt { class const_range_iterator; class range_iterator; /// /// A range is a 2D collection of cells with defined extens that can be iterated upon. /// class XLNT_API range { public: /// /// Alias for the iterator type /// using iterator = range_iterator; /// /// Alias for the const iterator type /// using const_iterator = const_range_iterator; /// /// Alias for the reverse iterator type /// using reverse_iterator = std::reverse_iterator; /// /// Alias for the const reverse iterator type /// using const_reverse_iterator = std::reverse_iterator; /// /// Constructs a range on the given worksheet. /// range(worksheet ws, const range_reference &reference, major_order order = major_order::row, bool skip_null = false); /// /// Desctructor /// ~range(); /// /// Default copy constructor. /// range(const range &) = default; /// /// Erases all cell data from the worksheet for cells within this range. /// void clear_cells(); /// /// Returns a vector pointing to the n-th row or column in this range (depending /// on major order). /// cell_vector vector(std::size_t n); /// /// Returns a vector pointing to the n-th row or column in this range (depending /// on major order). /// const cell_vector vector(std::size_t n) const; /// /// Returns a cell in the range relative to its top left cell. /// class cell cell(const cell_reference &ref); /// /// Returns a cell in the range relative to its top left cell. /// const class cell cell(const cell_reference &ref) const; /// /// The worksheet this range targets /// const worksheet &target_worksheet() const; /// /// Returns the reference defining the bounds of this range. /// range_reference reference() const; /// /// Returns the number of rows or columns in this range (depending on major order). /// std::size_t length() const; /// /// Returns true if the given cell exists in the parent worksheet of this range. /// bool contains(const cell_reference &ref); /// /// Sets the alignment of all cells in the range to new_alignment and returns the range. /// range alignment(const xlnt::alignment &new_alignment); /// /// Sets the border of all cells in the range to new_border and returns the range. /// range border(const xlnt::border &new_border); /// /// Sets the fill of all cells in the range to new_fill and returns the range. /// range fill(const xlnt::fill &new_fill); /// /// Sets the font of all cells in the range to new_font and returns the range. /// range font(const xlnt::font &new_font); /// /// Sets the number format of all cells in the range to new_number_format and /// returns the range. /// range number_format(const xlnt::number_format &new_number_format); /// /// Sets the protection of all cells in the range to new_protection and returns the range. /// range protection(const xlnt::protection &new_protection); /// /// Sets the named style applied to all cells in this range to a style named style_name. /// range style(const class style &new_style); /// /// Sets the named style applied to all cells in this range to a style named style_name. /// If this style has not been previously created in the workbook, a /// key_not_found exception will be thrown. /// range style(const std::string &style_name); /// /// /// xlnt::conditional_format conditional_format(const condition &when); /// /// Returns the first row or column in this range. /// cell_vector front(); /// /// Returns the first row or column in this range. /// const cell_vector front() const; /// /// Returns the last row or column in this range. /// cell_vector back(); /// /// Returns the last row or column in this range. /// const cell_vector back() const; /// /// Returns an iterator to the first row or column in this range. /// iterator begin(); /// /// Returns an iterator to one past the last row or column in this range. /// iterator end(); /// /// Returns an iterator to the first row or column in this range. /// const_iterator begin() const; /// /// Returns an iterator to one past the last row or column in this range. /// const_iterator end() const; /// /// Returns an iterator to the first row or column in this range. /// const_iterator cbegin() const; /// /// Returns an iterator to one past the last row or column in this range. /// const_iterator cend() const; /// /// Returns a reverse iterator to the first row or column in this range. /// reverse_iterator rbegin(); /// /// Returns a reverse iterator to one past the last row or column in this range. /// reverse_iterator rend(); /// /// Returns a reverse iterator to the first row or column in this range. /// const_reverse_iterator rbegin() const; /// /// Returns a reverse iterator to one past the last row or column in this range. /// const_reverse_iterator rend() const; /// /// Returns a reverse iterator to the first row or column in this range. /// const_reverse_iterator crbegin() const; /// /// Returns a reverse iterator to one past the last row or column in this range. /// const_reverse_iterator crend() const; /// /// Applies function f to all cells in the range /// void apply(std::function f); /// /// Returns the n-th row or column in this range. /// cell_vector operator[](std::size_t n); /// /// Returns the n-th row or column in this range. /// const cell_vector operator[](std::size_t n) const; /// /// Returns true if this range is equivalent to comparand. /// bool operator==(const range &comparand) const; /// /// Returns true if this range is not equivalent to comparand. /// bool operator!=(const range &comparand) const; private: /// /// The worksheet this range is within /// class worksheet ws_; /// /// The reference of this range /// range_reference ref_; /// /// Whether this range should be iterated by columns or rows first /// major_order order_; /// /// Whether null rows/columns and cells should be skipped during iteration /// bool skip_null_; }; } // namespace xlnt