From c7f61e38c13072e4befd323909c6f91eb52f946c Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Wed, 22 Mar 2017 21:44:59 -0400 Subject: [PATCH] restore worksheet::cell(column_t, row_t) method (#137) and move some single use classes/structs/enums into parent header --- include/xlnt/packaging/manifest.hpp | 12 +- include/xlnt/packaging/relationship.hpp | 18 +-- include/xlnt/packaging/uri.hpp | 91 ++++++++------- include/xlnt/styles/alignment.hpp | 40 +++++-- include/xlnt/styles/border.hpp | 97 ++++++++++------ .../xlnt/workbook/calculation_properties.hpp | 8 +- include/xlnt/workbook/document_security.hpp | 52 +++++++-- include/xlnt/workbook/named_range.hpp | 18 +-- include/xlnt/workbook/workbook_view.hpp | 34 +++--- include/xlnt/workbook/worksheet_iterator.hpp | 104 +++++++++++++++--- include/xlnt/worksheet/cell_iterator.hpp | 89 +++++++++++++++ include/xlnt/worksheet/cell_vector.hpp | 1 - include/xlnt/worksheet/page_setup.hpp | 52 ++++++++- include/xlnt/worksheet/range.hpp | 1 - include/xlnt/worksheet/range_iterator.hpp | 85 ++++++++++++++ include/xlnt/worksheet/worksheet.hpp | 12 ++ include/xlnt/xlnt.hpp | 13 +-- source/detail/custom_value_traits.hpp | 3 +- source/detail/xlsx_consumer.cpp | 1 - source/detail/xlsx_producer.cpp | 1 - source/packaging/uri.cpp | 4 +- source/styles/alignment.cpp | 9 +- source/styles/border.cpp | 18 ++- source/workbook/workbook.cpp | 1 - source/workbook/worksheet_iterator.cpp | 43 ++++++++ source/worksheet/cell_iterator.cpp | 73 ++++++++++++ source/worksheet/cell_vector.cpp | 2 +- source/worksheet/range.cpp | 1 - source/worksheet/range_iterator.cpp | 85 ++++++++++++++ source/worksheet/worksheet.cpp | 12 +- 30 files changed, 793 insertions(+), 187 deletions(-) diff --git a/include/xlnt/packaging/manifest.hpp b/include/xlnt/packaging/manifest.hpp index 60b57fbb..5aa2eae1 100644 --- a/include/xlnt/packaging/manifest.hpp +++ b/include/xlnt/packaging/manifest.hpp @@ -92,12 +92,12 @@ public: path canonicalize(const std::vector &rels) const; /// - /// + /// Registers a new relationship by specifying all of the relationship properties explicitly. /// std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode); /// - /// + /// Registers a new relationship already constructed elsewhere. /// std::string register_relationship(const class relationship &rel); @@ -174,22 +174,22 @@ public: private: /// - /// + /// Returns the lowest rId for the given part that hasn't already been registered. /// std::string next_relationship_id(const path &part) const; /// - /// + /// The map of extensions to default content types. /// std::unordered_map default_content_types_; /// - /// + /// The map of package parts to overriding content types. /// std::unordered_map override_content_types_; /// - /// + /// The map of package parts to their registered relationships. /// std::unordered_map> relationships_; }; diff --git a/include/xlnt/packaging/relationship.hpp b/include/xlnt/packaging/relationship.hpp index a561d6c6..3b6c1921 100644 --- a/include/xlnt/packaging/relationship.hpp +++ b/include/xlnt/packaging/relationship.hpp @@ -102,15 +102,15 @@ class XLNT_API relationship { public: /// - /// + /// Constructs a new empty relationship. /// relationship(); /// - /// + /// Constructs a new relationship by specifying all of its properties. /// - relationship( - const std::string &id, relationship_type t, const uri &source, const uri &target, xlnt::target_mode mode); + relationship(const std::string &id, relationship_type t, const uri &source, + const uri &target, xlnt::target_mode mode); /// /// Returns a string of the form rId# that identifies the relationship. @@ -149,27 +149,27 @@ public: private: /// - /// + /// The id of this relationship in the format "rId#" /// std::string id_; /// - /// + /// The type of this relationship. /// relationship_type type_; /// - /// + /// The URI of the source of this relationship. /// uri source_; /// - /// + /// The URI of the target of this relationshp. /// uri target_; /// - /// + /// Whether the target of this relationship is internal or external. /// xlnt::target_mode mode_; }; diff --git a/include/xlnt/packaging/uri.hpp b/include/xlnt/packaging/uri.hpp index a643ffa6..d1e5ee90 100644 --- a/include/xlnt/packaging/uri.hpp +++ b/include/xlnt/packaging/uri.hpp @@ -31,194 +31,207 @@ namespace xlnt { /// -/// +/// Encapsulates a uniform resource identifier (URI) as described +/// by RFC 3986. /// class XLNT_API uri { public: /// - /// + /// Constructs an empty URI. /// uri(); /// - /// + /// Constructs a URI by combining base with relative. /// uri(const uri &base, const uri &relative); /// - /// + /// Constructs a URI by combining base with relative path. /// uri(const uri &base, const path &relative); /// - /// + /// Constructs a URI by parsing the given uri_string. /// uri(const std::string &uri_string); /// - /// + /// Returns true if this URI is relative. /// bool is_relative() const; /// - /// + /// Returns true if this URI is not relative (i.e. absolute). /// bool is_absolute() const; /// - /// + /// Returns the scheme of this URI. + /// E.g. the scheme of http://user:pass@example.com is "http" /// std::string scheme() const; /// - /// + /// Returns the authority of this URI. + /// E.g. the authority of http://user:pass@example.com:80/document is "user:pass@example.com:80" /// std::string authority() const; /// - /// + /// Returns true if an authentication section is specified for this URI. /// bool has_authentication() const; /// - /// + /// Returns the authentication of this URI. + /// E.g. the authentication of http://user:pass@example.com is "user:pass" /// std::string authentication() const; /// - /// + /// Returns the username of this URI. + /// E.g. the username of http://user:pass@example.com is "user" /// std::string username() const; /// - /// + /// Returns the password of this URI. + /// E.g. the password of http://user:pass@example.com is "pass" /// std::string password() const; /// - /// + /// Returns the host of this URI. + /// E.g. the host of http://example.com:80/document is "example.com" /// std::string host() const; /// - /// + /// Returns true if a non-default port is specified for this URI. /// bool has_port() const; /// - /// + /// Returns the port of this URI. + /// E.g. the port of https://example.com:443/document is "443" /// std::size_t port() const; /// - /// + /// Returns the path of this URI. + /// E.g. the path of http://example.com/document is "/document" /// class path path() const; /// - /// + /// Returns true if this URI has a non-null query string section. /// bool has_query() const; /// - /// + /// Returns the query string of this URI. + /// E.g. the query of http://example.com/document?v=1&x=3#abc is "v=1&x=3" /// std::string query() const; /// - /// + /// Returns true if this URI has a non-empty fragment section. /// bool has_fragment() const; /// - /// + /// Returns the fragment section of this URI. + /// E.g. the fragment of http://example.com/document#abc is "abc" /// std::string fragment() const; /// - /// + /// Returns a string representation of this URI. /// std::string to_string() const; /// - /// + /// If this URI is relative, an absolute URI will be returned by appending + /// the path to the given absolute base URI. /// uri make_absolute(const uri &base); /// - /// + /// If this URI is absolute, a relative URI will be returned by removing the + /// common base path from the given absolute base URI. /// uri make_reference(const uri &base); /// - /// + /// Returns true if this URI is equivalent to other. /// - friend XLNT_API bool operator==(const uri &left, const uri &right); + bool operator==(const uri &other) const; private: /// - /// + /// True if this URI is absolute. /// bool absolute_ = false; /// - /// + /// The scheme, like "http" /// std::string scheme_; /// - /// + /// True if this URI has an authentication section. /// bool has_authentication_ = false; /// - /// + /// The username /// std::string username_; /// - /// + /// The password /// std::string password_; /// - /// + /// The host /// std::string host_; /// - /// + /// True if this URI has a non-default port specified /// bool has_port_ = false; /// - /// + /// The numeric port /// std::size_t port_ = 0; /// - /// + /// True if this URI has a query section /// bool has_query_ = false; /// - /// + /// The query section /// std::string query_; /// - /// + /// True if this URI has a fragment section /// bool has_fragment_ = false; /// - /// + /// The fragment section /// std::string fragment_; /// - /// + /// The path section /// class path path_; }; diff --git a/include/xlnt/styles/alignment.hpp b/include/xlnt/styles/alignment.hpp index 289c73d6..dc6417f9 100644 --- a/include/xlnt/styles/alignment.hpp +++ b/include/xlnt/styles/alignment.hpp @@ -25,12 +25,37 @@ #pragma once #include -#include -#include #include namespace xlnt { +/// +/// Text can be aligned horizontally in these enumerated ways. +/// +enum class XLNT_API horizontal_alignment +{ + general, + left, + center, + right, + fill, + justify, + center_continuous, + distributed +}; + +/// +/// Text can be aligned vertically in these enumerated ways. +/// +enum class XLNT_API vertical_alignment +{ + top, + center, + bottom, + justify, + distributed +}; + /// /// Alignment options for use in cell formats. /// @@ -98,17 +123,14 @@ public: alignment &vertical(vertical_alignment vertical); /// - /// Returns true if left is exactly equal to right. + /// Returns true if this alignment is equivalent to other. /// - XLNT_API friend bool operator==(const alignment &left, const alignment &right); + bool operator==(const alignment &other) const; /// - /// Returns true if left is not exactly equal to right. + /// Returns true if this alignment is not equivalent to other. /// - XLNT_API friend bool operator!=(const alignment &left, const alignment &right) - { - return !(left == right); - } + bool operator!=(const alignment &other) const; private: bool shrink_to_fit_ = false; diff --git a/include/xlnt/styles/border.hpp b/include/xlnt/styles/border.hpp index ea6efeaa..5685d987 100644 --- a/include/xlnt/styles/border.hpp +++ b/include/xlnt/styles/border.hpp @@ -30,15 +30,13 @@ #include #include -#include #include -#include #include namespace xlnt { /// -/// +/// Enumerates the sides of a cell to which a border style can be applied. /// enum class XLNT_API border_side { @@ -51,6 +49,40 @@ enum class XLNT_API border_side horizontal }; +/// +/// +/// +enum class XLNT_API border_style +{ + none, + dashdot, + dashdotdot, + dashed, + dotted, + double_, + hair, + medium, + mediumdashdot, + mediumdashdotdot, + mediumdashed, + slantdashdot, + thick, + thin +}; + +/// +/// Cells can have borders that go from the top-left to bottom-right +/// or from the top-right to bottom-left, or both, or neither. +/// Used by style->border. +/// +enum class XLNT_API diagonal_direction +{ + neither, + up, + down, + both +}; + } // namespace xlnt namespace xlnt { @@ -62,139 +94,132 @@ class XLNT_API border { public: /// - /// + /// Each side of a cell can have a border_property applied to it to change + /// how it is displayed. /// class XLNT_API border_property { public: /// - /// + /// Returns the color of the side. /// optional color() const; /// - /// + /// Sets the color of the side and returns a reference to the side properties. /// border_property &color(const xlnt::color &c); /// - /// + /// Returns the style of the side. /// optional style() const; /// - /// + /// Sets the style of the side and returns a reference to the side properties. /// border_property &style(border_style style); /// /// Returns true if left is exactly equal to right. /// - friend bool operator==(const border_property &left, const border_property &right); + bool operator==(const border_property &right) const; /// /// Returns true if left is not exactly equal to right. /// - friend bool operator!=(const border_property &left, const border_property &right) - { - return !(left == right); - } + bool operator!=(const border_property &right) const; private: /// - /// + /// The color of the side /// optional color_; /// - /// + /// The style of the side /// optional style_; }; /// - /// + /// A vector to the all of the border sides for iteration. /// static const std::vector &all_sides(); /// - /// + /// Constructs a default border. /// border(); /// - /// + /// Returns the border properties of the given side. /// optional side(border_side s) const; /// - /// + /// Sets the border properties of the side s to prop. /// border &side(border_side s, const border_property &prop); /// - /// + /// Returns the diagonal direction of this border. /// optional diagonal() const; /// - /// + /// Sets the diagonal direction of this border to dir. /// border &diagonal(diagonal_direction dir); /// /// Returns true if left is exactly equal to right. /// - XLNT_API friend bool operator==(const border &left, const border &right); + bool operator==(const border &right) const; /// /// Returns true if left is not exactly equal to right. /// - XLNT_API friend bool operator!=(const border &left, const border &right) - { - return !(left == right); - } + bool operator!=(const border &right) const; private: /// - /// + /// Start side (i.e. left) border properties /// optional start_; /// - /// + /// End side (i.e. right) border properties /// optional end_; /// - /// + /// Top side border properties /// optional top_; /// - /// + /// Bottom side border properties /// optional bottom_; /// - /// + /// Vertical border properties /// optional vertical_; /// - /// + /// Horizontal border properties /// optional horizontal_; /// - /// + /// Diagonal border properties /// optional diagonal_; - // bool outline_ = true; - /// - /// + /// Direction of diagonal border properties to be applied /// optional diagonal_direction_; }; diff --git a/include/xlnt/workbook/calculation_properties.hpp b/include/xlnt/workbook/calculation_properties.hpp index 49f79259..b1f85c6a 100644 --- a/include/xlnt/workbook/calculation_properties.hpp +++ b/include/xlnt/workbook/calculation_properties.hpp @@ -28,18 +28,20 @@ namespace xlnt { /// -/// +/// Workbook file properties relating to calculations. /// class XLNT_API calculation_properties { public: /// - /// Uniquely identifies these calculation properties. + /// The version of calculation engine used to calculate cell formula values. + /// If this is older than the version of the Excel calculation engine opening + /// the workbook, cell values will be recalculated. /// std::size_t calc_id; /// - /// If this is true, concurrent calculation is enabled. + /// If this is true, concurrent calculation will be enabled for the workbook. /// bool concurrent_calc; }; diff --git a/include/xlnt/workbook/document_security.hpp b/include/xlnt/workbook/document_security.hpp index 508ab764..52256384 100644 --- a/include/xlnt/workbook/document_security.hpp +++ b/include/xlnt/workbook/document_security.hpp @@ -31,40 +31,68 @@ namespace xlnt { /// -/// Security information about the OOXML document. +/// Properties governing how the data in a workbook should be protected. +/// These values can be ignored by consumers. /// class XLNT_API document_security { public: /// - /// + /// Holds data describing the verifier that locks revisions or a workbook. + /// + struct lock_verifier + { + /// + /// + /// + std::string hash_algorithm; + + /// + /// + /// + std::string salt; + + /// + /// + /// + std::string hash; + + /// + /// + /// + std::size_t spin_count; + }; + + /// + /// Constructs a new document security object with default values. /// document_security(); /// - /// + /// If true, the workbook is locked for revisions. /// - bool lock_revision; + bool lock_revision = false; /// - /// + /// If true, worksheets can't be moved, renamed, (un)hidden, inserted, or deleted. /// - bool lock_structure; + bool lock_structure = false; /// - /// + /// If true, workbook windows will be opened at the same position with the same size + /// every time they are loaded. /// - bool lock_windows; + bool lock_windows = false; /// - /// + /// The settings to allow the revision lock to be removed. /// - std::string revision_password; + lock_verifier revision_lock; /// - /// + /// The settings to allow the structure and windows lock to be removed. /// - std::string workbook_password; + lock_verifier workbook_lock; }; } // namespace xlnt diff --git a/include/xlnt/workbook/named_range.hpp b/include/xlnt/workbook/named_range.hpp index ffab8172..80156684 100644 --- a/include/xlnt/workbook/named_range.hpp +++ b/include/xlnt/workbook/named_range.hpp @@ -42,48 +42,48 @@ class XLNT_API named_range { public: /// - /// + /// Type alias for the combination of sheet and range this named_range points to. /// using target = std::pair; /// - /// + /// Constructs a named range that has no name and has no targets. /// named_range(); /// - /// + /// Constructs a named range by copying its name and targets from other. /// named_range(const named_range &other); /// - /// + /// Constructs a named range with the given name and targets. /// named_range(const std::string &name, const std::vector &targets); /// - /// + /// Returns the name of this range. /// std::string name() const; /// - /// + /// Returns the set of targets of this named range as a vector. /// const std::vector &targets() const; /// - /// + /// Assigns the name and targets of this named_range to that of other. /// named_range &operator=(const named_range &other); private: /// - /// + /// The name of this named range. /// std::string name_; /// - /// + /// The targets of this named range. /// std::vector targets_; }; diff --git a/include/xlnt/workbook/workbook_view.hpp b/include/xlnt/workbook/workbook_view.hpp index bde91d31..b2c57029 100644 --- a/include/xlnt/workbook/workbook_view.hpp +++ b/include/xlnt/workbook/workbook_view.hpp @@ -37,67 +37,67 @@ class XLNT_API workbook_view { public: /// - /// + /// If true, dates will be grouped when presenting the user with filtering options. /// - bool auto_filter_date_grouping = false; + bool auto_filter_date_grouping = true; /// - /// + /// If true, the view will be minimized. /// bool minimized = false; /// - /// + /// If true, the horizontal scroll bar will be displayed. /// - bool show_horizontal_scroll = false; + bool show_horizontal_scroll = true; /// - /// + /// If true, the sheet tabs will be displayed. /// - bool show_sheet_tabs = false; + bool show_sheet_tabs = true; /// - /// + /// If true, the vertical scroll bar will be displayed. /// - bool show_vertical_scroll = false; + bool show_vertical_scroll = true; /// - /// + /// If true, the workbook window will be visible. /// bool visible = true; /// - /// + /// The optional index to the active sheet in this view. /// optional active_tab; /// - /// + /// The optional index to the first sheet in this view. /// optional first_sheet; /// - /// + /// The optional ratio between the tabs bar and the horizontal scroll bar. /// optional tab_ratio; /// - /// + /// The width of the workbook window in twips. /// optional window_width; /// - /// + /// The height of the workbook window in twips. /// optional window_height; /// - /// + /// The distance of the workbook window from the left side of the screen in twips. /// optional x_window; /// - /// + /// The distance of the workbook window from the top of the screen in twips. /// optional y_window; }; diff --git a/include/xlnt/workbook/worksheet_iterator.hpp b/include/xlnt/workbook/worksheet_iterator.hpp index d78d1604..f73348e4 100644 --- a/include/xlnt/workbook/worksheet_iterator.hpp +++ b/include/xlnt/workbook/worksheet_iterator.hpp @@ -33,6 +33,10 @@ namespace xlnt { class workbook; class worksheet; +// Note: There are const and non-const implementations of this iterator +// because one needs to point at a const workbook and the other needs +// to point at a non-const workbook stored as a member variable, respectively. + /// /// Alias the parent class of this iterator to increase clarity. /// @@ -40,62 +44,132 @@ using ws_iter_type = std::iterator; /// -/// +/// An iterator which is used to iterate over the worksheets in a workbook. /// class XLNT_API worksheet_iterator : public ws_iter_type { public: /// - /// + /// Constructs a worksheet iterator from a workbook and sheet index. /// worksheet_iterator(workbook &wb, std::size_t index); /// - /// + /// Copy constructs a worksheet iterator from another iterator. /// worksheet_iterator(const worksheet_iterator &); /// - /// + /// Assigns the iterator so that it points to the same worksheet in the same workbook. /// worksheet_iterator &operator=(const worksheet_iterator &); /// - /// + /// Dereferences the iterator to return the worksheet it is pointing to. + /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter + /// exception will be thrown. /// worksheet operator*(); /// - /// + /// Returns true if this iterator points to the same worksheet as comparand. /// bool operator==(const worksheet_iterator &comparand) const; /// - /// + /// Returns true if this iterator doesn't point to the same worksheet as comparand. /// - bool operator!=(const worksheet_iterator &comparand) const - { - return !(*this == comparand); - } + bool operator!=(const worksheet_iterator &comparand) const; /// - /// + /// Post-increment the iterator's internal workseet index. Returns a copy of the + /// iterator as it was before being incremented. /// worksheet_iterator operator++(int); /// - /// + /// Pre-increment the iterator's internal workseet index. Returns a refernce + /// to the same iterator. /// worksheet_iterator &operator++(); private: /// - /// + /// The target workbook of this iterator. /// workbook &wb_; /// - /// + /// The index of the worksheet in wb_ this iterator is currently pointing to. + /// + std::size_t index_; +}; + + +/// +/// Alias the parent class of this iterator to increase clarity. +/// +using c_ws_iter_type = std::iterator; + +/// +/// An iterator which is used to iterate over the worksheets in a const workbook. +/// +class XLNT_API const_worksheet_iterator : public c_ws_iter_type +{ +public: + /// + /// Constructs a worksheet iterator from a workbook and sheet index. + /// + const_worksheet_iterator(const workbook &wb, std::size_t index); + + /// + /// Copy constructs a worksheet iterator from another iterator. + /// + const_worksheet_iterator(const const_worksheet_iterator &); + + /// + /// Assigns the iterator so that it points to the same worksheet in the same workbook. + /// + const_worksheet_iterator &operator=(const const_worksheet_iterator &); + + /// + /// Dereferences the iterator to return the worksheet it is pointing to. + /// If the iterator points to one-past-the-end of the workbook, an invalid_parameter + /// exception will be thrown. + /// + const worksheet operator*(); + + /// + /// Returns true if this iterator points to the same worksheet as comparand. + /// + bool operator==(const const_worksheet_iterator &comparand) const; + + /// + /// Returns true if this iterator doesn't point to the same worksheet as comparand. + /// + bool operator!=(const const_worksheet_iterator &comparand) const; + + /// + /// Post-increment the iterator's internal workseet index. Returns a copy of the + /// iterator as it was before being incremented. + /// + const_worksheet_iterator operator++(int); + + /// + /// Pre-increment the iterator's internal workseet index. Returns a refernce + /// to the same iterator. + /// + const_worksheet_iterator &operator++(); + +private: + /// + /// The target workbook of this iterator. + /// + const workbook &wb_; + + /// + /// The index of the worksheet in wb_ this iterator is currently pointing to. /// std::size_t index_; }; diff --git a/include/xlnt/worksheet/cell_iterator.hpp b/include/xlnt/worksheet/cell_iterator.hpp index 3b98476b..da1de712 100644 --- a/include/xlnt/worksheet/cell_iterator.hpp +++ b/include/xlnt/worksheet/cell_iterator.hpp @@ -129,4 +129,93 @@ private: major_order order_; }; +/// +/// Alias the parent class of this iterator to increase clarity. +/// +using cc_iter_type = std::iterator; + +/// +/// +/// +class XLNT_API const_cell_iterator : public cc_iter_type +{ +public: + /// + /// + /// + const_cell_iterator(worksheet ws, const cell_reference &start_cell); + + /// + /// + /// + const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order); + + /// + /// + /// + const_cell_iterator(const const_cell_iterator &other); + + /// + /// + /// + const_cell_iterator &operator=(const const_cell_iterator &) = default; + + /// + /// + /// + const cell operator*() const; + + /// + /// + /// + bool operator==(const const_cell_iterator &other) const; + + /// + /// + /// + bool operator!=(const const_cell_iterator &other) const; + + /// + /// + /// + const_cell_iterator &operator--(); + + /// + /// + /// + const_cell_iterator operator--(int); + + /// + /// + /// + const_cell_iterator &operator++(); + + /// + /// + /// + const_cell_iterator operator++(int); + +private: + /// + /// + /// + worksheet ws_; + + /// + /// + /// + cell_reference current_cell_; + + /// + /// + /// + range_reference range_; + + /// + /// + /// + major_order order_; +}; + } // namespace xlnt diff --git a/include/xlnt/worksheet/cell_vector.hpp b/include/xlnt/worksheet/cell_vector.hpp index 9ed29dd9..9019bbb4 100644 --- a/include/xlnt/worksheet/cell_vector.hpp +++ b/include/xlnt/worksheet/cell_vector.hpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/include/xlnt/worksheet/page_setup.hpp b/include/xlnt/worksheet/page_setup.hpp index a8402316..d8358f7f 100644 --- a/include/xlnt/worksheet/page_setup.hpp +++ b/include/xlnt/worksheet/page_setup.hpp @@ -25,13 +25,57 @@ #pragma once #include -#include -#include -#include -#include namespace xlnt { +/// +/// The orientation of the worksheet when it is printed. +/// +enum class XLNT_API orientation +{ + portrait, + landscape +}; + +/// +/// The types of page breaks. +/// +enum class XLNT_API page_break +{ + none = 0, + row = 1, + column = 2 +}; + +/// +/// The possible paper sizes for printing. +/// +enum class XLNT_API paper_size +{ + letter = 1, + letter_small = 2, + tabloid = 3, + ledger = 4, + legal = 5, + statement = 6, + executive = 7, + a3 = 8, + a4 = 9, + a4_small = 10, + a5 = 11 +}; + +/// +/// Defines how a worksheet appears in the workbook. +/// A workbook must have at least one sheet which is visible at all times. +/// +enum class XLNT_API sheet_state +{ + visible, + hidden, + very_hidden +}; + /// /// Describes how a worksheet will be converted into a page during printing. /// diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index e5668bcd..348cc576 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -31,7 +31,6 @@ #include #include -#include #include #include #include diff --git a/include/xlnt/worksheet/range_iterator.hpp b/include/xlnt/worksheet/range_iterator.hpp index 461bcea1..4e86f23c 100644 --- a/include/xlnt/worksheet/range_iterator.hpp +++ b/include/xlnt/worksheet/range_iterator.hpp @@ -121,4 +121,89 @@ private: major_order order_; }; +/// +/// Alias the parent class of this iterator to increase clarity. +/// +using cr_iter_type = std::iterator; + +/// +/// A const version of range_iterator which does not allow modification +/// to the dereferenced cell_vector. +/// +class XLNT_API const_range_iterator : public cr_iter_type +{ +public: + /// + /// + /// + const_range_iterator(const worksheet &ws, const range_reference &start_cell, major_order order = major_order::row); + + /// + /// + /// + const_range_iterator(const const_range_iterator &other); + + /// + /// + /// + const cell_vector operator*() const; + + /// + /// + /// + const_range_iterator &operator=(const const_range_iterator &) = default; + + /// + /// + /// + bool operator==(const const_range_iterator &other) const; + + /// + /// + /// + bool operator!=(const const_range_iterator &other) const; + + /// + /// + /// + const_range_iterator &operator--(); + + /// + /// + /// + const_range_iterator operator--(int); + + /// + /// + /// + const_range_iterator &operator++(); + + /// + /// + /// + const_range_iterator operator++(int); + +private: + /// + /// + /// + detail::worksheet_impl *ws_; + + /// + /// + /// + cell_reference current_cell_; + + /// + /// + /// + range_reference range_; + + /// + /// + /// + major_order order_; +}; + } // namespace xlnt diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 49aee891..4c0ca568 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -188,6 +188,18 @@ public: /// const class cell cell(const cell_reference &reference) const; + /// + /// Returns the cell at the given column and row. If the cell doesn't exist, it + /// will be initialized to null before being returned. + /// + class cell cell(column_t column, row_t row); + + /// + /// Returns the cell at the given column and row. If the cell doesn't exist, an + /// invalid_parameter exception will be thrown. + /// + const class cell cell(column_t column, row_t row) const; + /// /// Returns the range defined by reference string. If reference string is the name of /// a previously-defined named range in the sheet, it will be returned. diff --git a/include/xlnt/xlnt.hpp b/include/xlnt/xlnt.hpp index 8fc0e4ec..db839c3a 100644 --- a/include/xlnt/xlnt.hpp +++ b/include/xlnt/xlnt.hpp @@ -37,21 +37,18 @@ // packaging #include #include +#include // styles #include #include -#include #include -#include #include #include #include -#include #include #include #include -#include // utils #include @@ -64,7 +61,6 @@ #include // workbook -#include #include #include #include @@ -77,24 +73,17 @@ #include #include #include -#include -#include #include #include #include -#include -#include #include #include #include -#include #include #include #include #include #include #include -#include #include #include -#include diff --git a/source/detail/custom_value_traits.hpp b/source/detail/custom_value_traits.hpp index 7e0fd9e5..b3ecacbe 100644 --- a/source/detail/custom_value_traits.hpp +++ b/source/detail/custom_value_traits.hpp @@ -3,11 +3,10 @@ #include #include #include +#include #include #include #include -#include -#include #include #include #include diff --git a/source/detail/xlsx_consumer.cpp b/source/detail/xlsx_consumer.cpp index 38d2b42b..70d30a32 100755 --- a/source/detail/xlsx_consumer.cpp +++ b/source/detail/xlsx_consumer.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/source/detail/xlsx_producer.cpp b/source/detail/xlsx_producer.cpp index 59441e61..b845dcc8 100755 --- a/source/detail/xlsx_producer.cpp +++ b/source/detail/xlsx_producer.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/source/packaging/uri.cpp b/source/packaging/uri.cpp index 66d8b367..10b43777 100644 --- a/source/packaging/uri.cpp +++ b/source/packaging/uri.cpp @@ -21,9 +21,9 @@ path uri::path() const return path_; } -bool operator==(const uri &left, const uri &right) +bool uri::operator==(const uri &other) const { - return left.to_string() == right.to_string(); + return to_string() == other.to_string(); } } // namespace xlnt diff --git a/source/styles/alignment.cpp b/source/styles/alignment.cpp index 25a26650..5a155ecd 100644 --- a/source/styles/alignment.cpp +++ b/source/styles/alignment.cpp @@ -92,8 +92,10 @@ optional alignment::rotation() const return text_rotation_; } -XLNT_API bool operator==(const alignment &left, const alignment &right) +bool alignment::operator==(const alignment &right) const { + auto &left = *this; + if (left.horizontal().is_set() != right.horizontal().is_set()) { return false; @@ -159,4 +161,9 @@ XLNT_API bool operator==(const alignment &left, const alignment &right) return true; } +bool alignment::operator!=(const alignment &other) const +{ + return !(*this == other); +} + } // namespace xlnt diff --git a/source/styles/border.cpp b/source/styles/border.cpp index a9762d73..75d3c0df 100644 --- a/source/styles/border.cpp +++ b/source/styles/border.cpp @@ -50,8 +50,10 @@ border::border_property &border::border_property::style(border_style s) return *this; } -bool operator==(const border::border_property &left, const border::border_property &right) +bool border::border_property::operator==(const border::border_property &right) const { + auto &left = *this; + if (left.style().is_set() != right.style().is_set()) { return false; @@ -81,6 +83,11 @@ bool operator==(const border::border_property &left, const border::border_proper return true; } +bool border::border_property::operator!=(const border::border_property &right) const +{ + return !(*this == right); +} + border::border() { } @@ -158,8 +165,10 @@ optional border::diagonal() const return diagonal_direction_; } -XLNT_API bool operator==(const border &left, const border &right) +bool border::operator==(const border &right) const { + auto &left = *this; + for (auto side : border::all_sides()) { if (left.side(side).is_set() != right.side(side).is_set()) @@ -179,4 +188,9 @@ XLNT_API bool operator==(const border &left, const border &right) return true; } +bool border::operator!=(const border &right) const +{ + return !(*this == right); +} + } // namespace xlnt diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 9728e75b..b01d1895 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include diff --git a/source/workbook/worksheet_iterator.cpp b/source/workbook/worksheet_iterator.cpp index c3733520..424e1a44 100644 --- a/source/workbook/worksheet_iterator.cpp +++ b/source/workbook/worksheet_iterator.cpp @@ -60,10 +60,53 @@ bool worksheet_iterator::operator==(const worksheet_iterator &comparand) const return index_ == comparand.index_ && wb_ == comparand.wb_; } +bool worksheet_iterator::operator!=(const worksheet_iterator &comparand) const +{ + return !(*this == comparand); +} + worksheet_iterator &worksheet_iterator::operator=(const worksheet_iterator &other) { index_ = other.index_; return *this; } +const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size_t index) + : wb_(wb), index_(index) +{ +} + +const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterator &rhs) + : wb_(rhs.wb_), index_(rhs.index_) +{ +} + +const worksheet const_worksheet_iterator::operator*() +{ + return wb_.sheet_by_index(index_); +} + +const_worksheet_iterator &const_worksheet_iterator::operator++() +{ + index_++; + return *this; +} + +const_worksheet_iterator const_worksheet_iterator::operator++(int) +{ + const_worksheet_iterator old(wb_, index_); + ++*this; + return old; +} + +bool const_worksheet_iterator::operator==(const const_worksheet_iterator &comparand) const +{ + return index_ == comparand.index_ && wb_ == comparand.wb_; +} + +bool const_worksheet_iterator::operator!=(const const_worksheet_iterator &comparand) const +{ + return !(*this == comparand); +} + } // namespace xlnt diff --git a/source/worksheet/cell_iterator.cpp b/source/worksheet/cell_iterator.cpp index 333428f6..967a2e1e 100644 --- a/source/worksheet/cell_iterator.cpp +++ b/source/worksheet/cell_iterator.cpp @@ -131,4 +131,77 @@ cell cell_iterator::operator*() return ws_[current_cell_]; } + +const_cell_iterator::const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order) + : ws_(ws), + current_cell_(start_cell), + range_(start_cell.to_range()), + order_(order) +{ +} + +const_cell_iterator::const_cell_iterator(const const_cell_iterator &other) +{ + *this = other; +} + +bool const_cell_iterator::operator==(const const_cell_iterator &other) const +{ + return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_; +} + +bool const_cell_iterator::operator!=(const const_cell_iterator &other) const +{ + return !(*this == other); +} + +const_cell_iterator &const_cell_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.column_index(current_cell_.column_index() - 1); + } + else + { + current_cell_.row(current_cell_.row() - 1); + } + + return *this; +} + +const_cell_iterator const_cell_iterator::operator--(int) +{ + const_cell_iterator old = *this; + --*this; + + return old; +} + +const_cell_iterator &const_cell_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.column_index(current_cell_.column_index() + 1); + } + else + { + current_cell_.row(current_cell_.row() + 1); + } + + return *this; +} + +const_cell_iterator const_cell_iterator::operator++(int) +{ + const_cell_iterator old = *this; + ++*this; + + return old; +} + +const cell const_cell_iterator::operator*() const +{ + return ws_.cell(current_cell_); +} + } // namespace xlnt diff --git a/source/worksheet/cell_vector.cpp b/source/worksheet/cell_vector.cpp index d786520a..68a7d745 100644 --- a/source/worksheet/cell_vector.cpp +++ b/source/worksheet/cell_vector.cpp @@ -20,10 +20,10 @@ // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file + #include #include #include -#include namespace xlnt { diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index f356b5a6..2626db6a 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/source/worksheet/range_iterator.cpp b/source/worksheet/range_iterator.cpp index 28e3fed4..745edba1 100644 --- a/source/worksheet/range_iterator.cpp +++ b/source/worksheet/range_iterator.cpp @@ -127,4 +127,89 @@ range_iterator range_iterator::operator++(int) return old; } + +const_range_iterator::const_range_iterator(const worksheet &ws, + const range_reference &start_cell, major_order order) + : ws_(ws.d_), + current_cell_(start_cell.top_left()), + range_(start_cell), + order_(order) +{ +} + +const_range_iterator::const_range_iterator(const const_range_iterator &other) +{ + *this = other; +} + +bool const_range_iterator::operator==(const const_range_iterator &other) const +{ + return ws_ == other.ws_ + && current_cell_ == other.current_cell_ + && order_ == other.order_; +} + +bool const_range_iterator::operator!=(const const_range_iterator &other) const +{ + return !(*this == other); +} + +const_range_iterator &const_range_iterator::operator--() +{ + if (order_ == major_order::row) + { + current_cell_.row(current_cell_.row() - 1); + } + else + { + current_cell_.column_index(current_cell_.column_index() - 1); + } + + return *this; +} + +const_range_iterator const_range_iterator::operator--(int) +{ + const_range_iterator old = *this; + --*this; + + return old; +} + +const_range_iterator &const_range_iterator::operator++() +{ + if (order_ == major_order::row) + { + current_cell_.row(current_cell_.row() + 1); + } + else + { + current_cell_.column_index(current_cell_.column_index() + 1); + } + + return *this; +} + +const_range_iterator const_range_iterator::operator++(int) +{ + const_range_iterator old = *this; + ++*this; + + return old; +} + +const cell_vector const_range_iterator::operator*() const +{ + if (order_ == major_order::row) + { + range_reference reference(range_.top_left().column_index(), current_cell_.row(), + range_.bottom_right().column_index(), current_cell_.row()); + return cell_vector(ws_, reference, order_); + } + + range_reference reference(current_cell_.column_index(), range_.top_left().row(), + current_cell_.column_index(), range_.bottom_right().row()); + return cell_vector(ws_, reference, order_); +} + } // namespace xlnt diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 49ccc1db..5725f4f5 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -36,8 +36,6 @@ #include #include #include -#include -#include #include #include #include @@ -377,6 +375,16 @@ const cell worksheet::cell(const cell_reference &reference) const return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index())); } +cell worksheet::cell(xlnt::column_t column, row_t row) +{ + return cell(cell_reference(column, row)); +} + +const cell worksheet::cell(xlnt::column_t column, row_t row) const +{ + return cell(cell_reference(column, row)); +} + bool worksheet::has_cell(const cell_reference &reference) const { const auto row = d_->cell_map_.find(reference.row());