From c55aac9ecfba84c33051bc6dc60ef52ecd3972ee Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Fri, 2 Dec 2016 14:37:50 +0100 Subject: [PATCH] rename getters and setters to the property name, many breaking changes\! --- include/xlnt/cell/cell.hpp | 90 +- include/xlnt/cell/cell_reference.hpp | 12 +- include/xlnt/cell/text_run.hpp | 73 +- include/xlnt/packaging/manifest.hpp | 30 +- include/xlnt/packaging/relationship.hpp | 21 +- include/xlnt/packaging/uri.hpp | 22 +- include/xlnt/styles/color.hpp | 66 +- include/xlnt/styles/font.hpp | 35 +- include/xlnt/styles/number_format.hpp | 10 +- include/xlnt/utils/datetime.hpp | 10 + include/xlnt/utils/exceptions.hpp | 2 +- include/xlnt/utils/path.hpp | 7 + include/xlnt/workbook/named_range.hpp | 6 +- include/xlnt/workbook/workbook.hpp | 263 +---- include/xlnt/worksheet/cell_vector.hpp | 9 +- include/xlnt/worksheet/footer.hpp | 8 +- include/xlnt/worksheet/header.hpp | 8 +- include/xlnt/worksheet/header_footer.hpp | 12 +- include/xlnt/worksheet/page_margins.hpp | 24 +- include/xlnt/worksheet/page_setup.hpp | 42 +- include/xlnt/worksheet/pane.hpp | 25 +- include/xlnt/worksheet/range.hpp | 10 +- include/xlnt/worksheet/range_reference.hpp | 12 +- include/xlnt/worksheet/selection.hpp | 30 +- include/xlnt/worksheet/sheet_protection.hpp | 4 +- include/xlnt/worksheet/sheet_view.hpp | 97 +- include/xlnt/worksheet/worksheet.hpp | 144 ++- samples/sample.cpp | 8 +- source/cell/cell.cpp | 266 ++--- source/cell/cell_reference.cpp | 20 +- source/cell/formatted_text.cpp | 14 +- source/cell/tests/test_cell.hpp | 471 ++++---- source/cell/tests/test_text.hpp | 20 +- source/cell/text_run.cpp | 103 +- source/detail/constants.cpp | 9 +- source/detail/constants.hpp | 4 +- source/detail/custom_value_traits.cpp | 74 +- source/detail/custom_value_traits.hpp | 49 +- source/detail/number_formatter.cpp | 4 +- source/detail/number_formatter.hpp | 2 +- source/detail/stylesheet.hpp | 10 +- source/detail/workbook_impl.hpp | 164 +-- source/detail/worksheet_impl.hpp | 7 +- source/detail/xlsx_consumer.cpp | 1085 ++++++++---------- source/detail/xlsx_consumer.hpp | 193 +++- source/detail/xlsx_crypto.cpp | 16 +- source/detail/xlsx_producer.cpp | 986 ++++++++-------- source/detail/xlsx_producer.hpp | 2 +- source/detail/zip.cpp | 28 +- source/detail/zip.hpp | 2 +- source/packaging/manifest.cpp | 58 +- source/packaging/relationship.cpp | 12 +- source/packaging/uri.cpp | 2 +- source/styles/color.cpp | 74 +- source/styles/font.cpp | 60 +- source/styles/format.cpp | 2 +- source/styles/number_format.cpp | 18 +- source/styles/style.cpp | 14 +- source/styles/tests/test_color.hpp | 20 +- source/styles/tests/test_fill.hpp | 22 +- source/styles/tests/test_number_format.hpp | 154 +-- source/utils/datetime.cpp | 43 + source/utils/exceptions.cpp | 4 +- source/utils/path.cpp | 23 + source/workbook/const_worksheet_iterator.cpp | 2 +- source/workbook/named_range.cpp | 4 +- source/workbook/tests/test_consume_xlsx.hpp | 20 +- source/workbook/tests/test_produce_xlsx.hpp | 136 +-- source/workbook/tests/test_round_trip.hpp | 5 +- source/workbook/tests/test_workbook.hpp | 124 +- source/workbook/workbook.cpp | 662 ++++------- source/worksheet/cell_iterator.cpp | 28 +- source/worksheet/cell_vector.cpp | 50 +- source/worksheet/const_cell_iterator.cpp | 10 +- source/worksheet/const_range_iterator.cpp | 18 +- source/worksheet/footer.cpp | 8 +- source/worksheet/header.cpp | 8 +- source/worksheet/header_footer.cpp | 12 +- source/worksheet/page_margins.cpp | 24 +- source/worksheet/page_setup.cpp | 34 +- source/worksheet/range.cpp | 76 +- source/worksheet/range_iterator.cpp | 24 +- source/worksheet/range_reference.cpp | 18 +- source/worksheet/sheet_protection.cpp | 4 +- source/worksheet/tests/test_page_setup.hpp | 30 +- source/worksheet/tests/test_worksheet.hpp | 566 ++++----- source/worksheet/worksheet.cpp | 391 ++++--- tests/helpers/xml_helper.hpp | 14 +- 88 files changed, 3564 insertions(+), 3819 deletions(-) diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp index dab9f1d7..5d0e37f2 100644 --- a/include/xlnt/cell/cell.hpp +++ b/include/xlnt/cell/cell.hpp @@ -106,7 +106,7 @@ public: /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. /// template - T get_value() const; + T value() const; /// /// Make this cell have a value of type null. @@ -120,17 +120,23 @@ public: /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. /// template - void set_value(T value); + void value(T value); + + /// + /// Analyze string_value to determine its type, convert it to that type, + /// and set the value of this cell to that converted value. + /// + void value(const std::string &string_value, bool infer_type); /// /// Return the type of this cell. /// - type get_data_type() const; + type data_type() const; /// /// Set the type of this cell. /// - void set_data_type(type t); + void data_type(type t); // properties @@ -150,34 +156,34 @@ public: /// /// Return a cell_reference that points to the location of this cell. /// - cell_reference get_reference() const; + cell_reference reference() const; /// /// Return the column of this cell. /// - column_t get_column() const; + column_t column() const; /// /// Return the row of this cell. /// - row_t get_row() const; + row_t row() const; /// /// Return the location of this cell as an ordered pair. /// - std::pair get_anchor() const; + std::pair anchor() const; // hyperlink /// /// Return the URL of this cell's hyperlink. /// - std::string get_hyperlink() const; + std::string hyperlink() const; /// /// Add a hyperlink to this cell pointing to the URI of the given value. /// - void set_hyperlink(const std::string &value); + void hyperlink(const std::string &value); /// /// Return true if this cell has a hyperlink set. @@ -187,32 +193,32 @@ public: // computed formatting /// - /// Returns the result of get_computed_format().get_alignment(). + /// Returns the result of computed_format().alignment(). /// alignment computed_alignment() const; /// - /// Returns the result of get_computed_format().get_border(). + /// Returns the result of computed_format().border(). /// border computed_border() const; /// - /// Returns the result of get_computed_format().get_fill(). + /// Returns the result of computed_format().fill(). /// fill computed_fill() const; /// - /// Returns the result of get_computed_format().get_font(). + /// Returns the result of computed_format().font(). /// font computed_font() const; /// - /// Returns the result of get_computed_format().get_number_format(). + /// Returns the result of computed_format().number_format(). /// number_format computed_number_format() const; /// - /// Returns the result of get_computed_format().get_protection(). + /// Returns the result of computed_format().protection(). /// protection computed_protection() const; @@ -244,68 +250,68 @@ public: /// /// Returns the number format of this cell. /// - number_format get_number_format() const; + number_format number_format() const; /// /// Creates a new format in the workbook, sets its number_format /// to the given format, and applies the format to this cell. /// - void set_number_format(const number_format &format); + void number_format(const class number_format &format); /// /// Returns the font applied to the text in this cell. /// - font get_font() const; + font font() const; /// /// Creates a new format in the workbook, sets its font /// to the given font, and applies the format to this cell. /// - void set_font(const font &font_); + void font(const class font &font_); /// /// Returns the fill applied to this cell. /// - fill get_fill() const; + fill fill() const; /// /// Creates a new format in the workbook, sets its fill /// to the given fill, and applies the format to this cell. /// - void set_fill(const fill &fill_); + void fill(const class fill &fill_); /// /// Returns the border of this cell. /// - border get_border() const; + border border() const; /// /// Creates a new format in the workbook, sets its border /// to the given border, and applies the format to this cell. /// - void set_border(const border &border_); + void border(const class border &border_); /// /// Returns the alignment of the text in this cell. /// - alignment get_alignment() const; + alignment alignment() const; /// /// Creates a new format in the workbook, sets its alignment /// to the given alignment, and applies the format to this cell. /// - void set_alignment(const alignment &alignment_); + void alignment(const class alignment &alignment_); /// /// Returns the protection of this cell. /// - protection get_protection() const; + protection protection() const; /// /// Creates a new format in the workbook, sets its protection /// to the given protection, and applies the format to this cell. /// - void set_protection(const protection &protection_); + void protection(const class protection &protection_); // style @@ -343,13 +349,13 @@ public: /// /// Returns the string representation of the formula applied to this cell. /// - std::string get_formula() const; + std::string formula() const; /// /// Sets the formula of this cell to the given value. /// This formula string should begin with '='. /// - void set_formula(const std::string &formula); + void formula(const std::string &formula); /// /// Removes the formula from this cell. After this is called, has_formula() will return false. @@ -387,17 +393,17 @@ public: /// Generally, this shouldn't be called directly. Instead, /// use worksheet::merge_cells on its parent worksheet. /// - void set_merged(bool merged); + void merged(bool merged); /// /// Return the error string that is stored in this cell. /// - std::string get_error() const; + std::string error() const; /// /// Directly assign the value of this cell to be the given error. /// - void set_error(const std::string &error); + void error(const std::string &error); /// /// Return a cell from this cell's parent workbook at @@ -408,28 +414,28 @@ public: /// /// Return the worksheet that owns this cell. /// - worksheet get_worksheet(); + worksheet worksheet(); /// /// Return the worksheet that owns this cell. /// - const worksheet get_worksheet() const; + const class worksheet worksheet() const; /// /// Return the workbook of the worksheet that owns this cell. /// - workbook &get_workbook(); + workbook &workbook(); /// /// Return the workbook of the worksheet that owns this cell. /// - const workbook &get_workbook() const; + const class workbook &workbook() const; /// /// Shortcut to return the base date of the parent workbook. - /// Equivalent to get_workbook().get_properties().excel_base_date + /// Equivalent to workbook().properties().excel_base_date /// - calendar get_base_date() const; + calendar base_date() const; /// /// Return to_check after checking encoding, size, and illegal characters. @@ -489,12 +495,6 @@ private: friend class detail::xlsx_producer; friend struct detail::cell_impl; - /// - /// Helper function to guess the type of a string, convert it, - /// and then use the correct cell::get_value according to the type. - /// - void guess_type_and_set_value(const std::string &value); - /// /// Returns a non-const reference to the format of this cell. /// This is for internal use only. diff --git a/include/xlnt/cell/cell_reference.hpp b/include/xlnt/cell/cell_reference.hpp index f5933ff4..f4fb5864 100644 --- a/include/xlnt/cell/cell_reference.hpp +++ b/include/xlnt/cell/cell_reference.hpp @@ -139,32 +139,32 @@ public: /// Return a string that identifies the column of this reference /// (e.g. second column from left is "B") /// - column_t get_column() const; + column_t column() const; /// /// Set the column of this reference from a string that identifies a particular column. /// - void set_column(const std::string &column_string); + void column(const std::string &column_string); /// /// Return a 1-indexed numeric index of the column of this reference. /// - column_t get_column_index() const; + column_t::index_t column_index() const; /// /// Set the column of this reference from a 1-indexed number that identifies a particular column. /// - void set_column_index(column_t column); + void column_index(column_t column); /// /// Return a 1-indexed numeric index of the row of this reference. /// - row_t get_row() const; + row_t row() const; /// /// Set the row of this reference from a 1-indexed number that identifies a particular row. /// - void set_row(row_t row); + void row(row_t row); /// /// Return a cell_reference offset from this cell_reference by diff --git a/include/xlnt/cell/text_run.hpp b/include/xlnt/cell/text_run.hpp index ff55d6d2..12a9f1c0 100644 --- a/include/xlnt/cell/text_run.hpp +++ b/include/xlnt/cell/text_run.hpp @@ -26,6 +26,7 @@ #include #include +#include #include namespace xlnt { @@ -56,12 +57,12 @@ public: /// /// /// - std::string get_string() const; + std::string string() const; /// /// /// - void set_string(const std::string &string); + void string(const std::string &string); /// /// @@ -71,12 +72,12 @@ public: /// /// /// - std::size_t get_size() const; + std::size_t size() const; /// /// /// - void set_size(std::size_t size); + void size(std::size_t size); /// /// @@ -86,12 +87,12 @@ public: /// /// /// - color get_color() const; + color color() const; /// /// /// - void set_color(const color &new_color); + void color(const class color &new_color); /// /// @@ -101,12 +102,12 @@ public: /// /// /// - std::string get_font() const; + std::string font() const; /// /// /// - void set_font(const std::string &font); + void font(const std::string &font); /// /// @@ -116,12 +117,12 @@ public: /// /// /// - std::size_t get_family() const; + std::size_t family() const; /// /// /// - void set_family(std::size_t family); + void family(std::size_t family); /// /// @@ -131,27 +132,42 @@ public: /// /// /// - std::string get_scheme() const; + std::string scheme() const; /// /// /// - void set_scheme(const std::string &scheme); + void scheme(const std::string &scheme); /// /// /// - bool bold_set() const; + bool bold() const; /// /// /// - bool is_bold() const; + void bold(bool bold); /// /// /// - void set_bold(bool bold); + bool underline_set() const; + + /// + /// + /// + bool underlined() const; + + /// + /// + /// + font::underline_style underline() const; + + /// + /// + /// + void underline(font::underline_style style); private: /// @@ -162,32 +178,7 @@ private: /// /// /// - optional size_; - - /// - /// - /// - optional color_; - - /// - /// - /// - optional font_; - - /// - /// - /// - optional family_; - - /// - /// - /// - optional scheme_; - - /// - /// - /// - optional bold_; + optional font_; }; } // namespace xlnt diff --git a/include/xlnt/packaging/manifest.hpp b/include/xlnt/packaging/manifest.hpp index 974f02f5..a0fe917b 100644 --- a/include/xlnt/packaging/manifest.hpp +++ b/include/xlnt/packaging/manifest.hpp @@ -48,14 +48,14 @@ public: /// Returns the path to all internal package parts registered as a source /// or target of a relationship. /// - std::vector get_parts() const; + std::vector parts() const; // Relationships /// /// Returns true if the manifest contains a relationship with the given type with part as the source. /// - bool has_relationship(const path &source, relationship::type type) const; + bool has_relationship(const path &source, relationship_type type) const; /// /// Returns true if the manifest contains a relationship with the given type with part as the source. @@ -66,39 +66,39 @@ public: /// Returns the relationship with "source" as the source and with a type of "type". /// Throws a key_not_found exception if no such relationship is found. /// - relationship get_relationship(const path &source, relationship::type type) const; + relationship relationship(const path &source, relationship_type type) const; /// /// Returns the relationship with "source" as the source and with an ID of "rel_id". /// Throws a key_not_found exception if no such relationship is found. /// - relationship get_relationship(const path &source, const std::string &rel_id) const; + class relationship relationship(const path &source, const std::string &rel_id) const; /// /// Returns all relationship with "source" as the source. /// - std::vector get_relationships(const path &source) const; + std::vector relationships(const path &source) const; /// /// Returns all relationships with "source" as the source and with a type of "type". /// - std::vector get_relationships(const path &source, relationship::type type) const; + std::vector relationships(const path &source, relationship_type type) const; /// /// Returns the canonical path of the chain of relationships by traversing through rels /// and forming the absolute combined path. /// - path canonicalize(const std::vector &rels) const; + path canonicalize(const std::vector &rels) const; /// /// /// - std::string register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode); + std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode); /// /// /// - std::string register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode, const std::string &rel_id); + std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode, const std::string &rel_id); /// /// @@ -110,7 +110,7 @@ public: /// /// Given the path to a part, returns the content type of the part as a string. /// - std::string get_content_type(const path &part) const; + std::string content_type(const path &part) const; // Default Content Types @@ -122,12 +122,12 @@ public: /// /// Returns a vector of all extensions with registered default content types. /// - std::vector get_extensions_with_default_types() const; + std::vector extensions_with_default_types() const; /// /// Returns the registered default content type for parts of the given extension. /// - std::string get_default_type(const std::string &extension) const; + std::string default_type(const std::string &extension) const; /// /// Associates the given extension with the given content type. @@ -151,12 +151,12 @@ public: /// Returns the override content type registered for the given part. /// Throws key_not_found exception if no override type was found. /// - std::string get_override_type(const path &part) const; + std::string override_type(const path &part) const; /// /// Returns the path of every part in this manifest with an overriden content type. /// - std::vector get_parts_with_overriden_types() const; + std::vector parts_with_overriden_types() const; /// /// Overrides any default type registered for the part's extension with the given content type. @@ -187,7 +187,7 @@ private: /// /// /// - std::unordered_map> relationships_; + std::unordered_map> relationships_; }; } // namespace xlnt diff --git a/include/xlnt/packaging/relationship.hpp b/include/xlnt/packaging/relationship.hpp index 5352e109..168d389d 100644 --- a/include/xlnt/packaging/relationship.hpp +++ b/include/xlnt/packaging/relationship.hpp @@ -100,11 +100,6 @@ enum class XLNT_API relationship_type class XLNT_API relationship { public: - /// - /// - /// - using type = relationship_type; - /// /// /// @@ -113,32 +108,32 @@ public: /// /// /// - relationship(const std::string &id, type t, const uri &source, const uri &target, target_mode mode); + relationship(const std::string &id, relationship_type t, const uri &source, const uri &target, target_mode mode); /// /// Returns a string of the form rId# that identifies the relationship. /// - std::string get_id() const; + std::string id() const; /// /// Returns the type of this relationship. /// - type get_type() const; + relationship_type type() const; /// /// Returns whether the target of the relationship is internal or external to the package. /// - target_mode get_target_mode() const; + target_mode target_mode() const; /// /// Returns the URI of the package part this relationship points to. /// - uri get_source() const; + uri source() const; /// /// Returns the URI of the package part this relationship points to. /// - uri get_target() const; + uri target() const; /// /// Returns true if and only if rhs is equal to this relationship. @@ -159,7 +154,7 @@ private: /// /// /// - type type_; + relationship_type type_; /// /// @@ -174,7 +169,7 @@ private: /// /// /// - target_mode mode_; + enum target_mode mode_; }; } // namespace xlnt diff --git a/include/xlnt/packaging/uri.hpp b/include/xlnt/packaging/uri.hpp index 2001de8e..4ae214c7 100644 --- a/include/xlnt/packaging/uri.hpp +++ b/include/xlnt/packaging/uri.hpp @@ -68,12 +68,12 @@ public: /// /// /// - std::string get_scheme() const; + std::string scheme() const; /// /// /// - std::string get_authority() const; + std::string authority() const; /// /// @@ -83,22 +83,22 @@ public: /// /// /// - std::string get_authentication() const; + std::string authentication() const; /// /// /// - std::string get_username() const; + std::string username() const; /// /// /// - std::string get_password() const; + std::string password() const; /// /// /// - std::string get_host() const; + std::string host() const; /// /// @@ -108,12 +108,12 @@ public: /// /// /// - std::size_t get_port() const; + std::size_t port() const; /// /// /// - path get_path() const; + path path() const; /// /// @@ -123,7 +123,7 @@ public: /// /// /// - std::string get_query() const; + std::string query() const; /// /// @@ -133,7 +133,7 @@ public: /// /// /// - std::string get_fragment() const; + std::string fragment() const; /// /// @@ -219,7 +219,7 @@ private: /// /// /// - path path_; + class path path_; }; } // namespace xlnt diff --git a/include/xlnt/styles/color.hpp b/include/xlnt/styles/color.hpp index 60eff4c6..deb4327a 100644 --- a/include/xlnt/styles/color.hpp +++ b/include/xlnt/styles/color.hpp @@ -44,12 +44,12 @@ public: /// /// /// - std::size_t get_index() const; + std::size_t index() const; /// /// /// - void set_index(std::size_t index); + void index(std::size_t index); private: /// @@ -72,12 +72,12 @@ public: /// /// /// - std::size_t get_index() const; + std::size_t index() const; /// /// /// - void set_index(std::size_t index); + void index(std::size_t index); private: /// @@ -105,37 +105,37 @@ public: /// /// /// - std::string get_hex_string() const; + std::string hex_string() const; /// /// /// - std::uint8_t get_red() const; + std::uint8_t red() const; /// /// /// - std::uint8_t get_green() const; + std::uint8_t green() const; /// /// /// - std::uint8_t get_blue() const; + std::uint8_t blue() const; /// /// /// - std::uint8_t get_alpha() const; + std::uint8_t alpha() const; /// /// /// - std::array get_rgb() const; + std::array rgb() const; /// /// /// - std::array get_rgba() const; + std::array rgba() const; private: /// @@ -149,23 +149,22 @@ private: std::array rgba_; }; +/// +/// Some colors are references to colors rather than having a particular RGB value. +/// +enum class color_type +{ + indexed, + theme, + rgb +}; + /// /// Colors can be applied to many parts of a cell's style. /// class XLNT_API color { public: - /// - /// Some colors are references to colors rather than having a particular RGB value. - /// - enum class type - { - indexed, - theme, - rgb, - auto_ - }; - /// /// /// @@ -239,7 +238,7 @@ public: /// /// /// - type get_type() const; + color_type type() const; /// /// @@ -249,32 +248,32 @@ public: /// /// /// - void set_auto(bool value); + void auto_(bool value); /// /// /// - const rgb_color &get_rgb() const; + const rgb_color &rgb() const; /// /// /// - const indexed_color &get_indexed() const; + const indexed_color &indexed() const; /// /// /// - const theme_color &get_theme() const; + const theme_color &theme() const; /// /// /// - double get_tint() const; + double tint() const; /// /// /// - void set_tint(double tint); + void tint(double tint); /// /// @@ -290,12 +289,12 @@ private: /// /// /// - void assert_type(type t) const; + void assert_type(color_type t) const; /// /// /// - type type_; + color_type type_; /// /// @@ -316,6 +315,11 @@ private: /// /// double tint_; + + /// + /// + /// + bool auto__; }; } // namespace xlnt diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index 707e0b3a..c2212d6b 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -111,6 +111,11 @@ public: /// underline_style underline() const; + /// + /// + /// + bool has_size() const; + /// /// /// @@ -121,6 +126,11 @@ public: /// std::size_t size() const; + /// + /// + /// + bool has_name() const; + /// /// /// @@ -131,6 +141,11 @@ public: /// std::string name() const; + /// + /// + /// + bool has_color() const; + /// /// /// @@ -139,7 +154,12 @@ public: /// /// /// - optional color() const; + xlnt::color color() const; + + /// + /// + /// + bool has_family() const; /// /// @@ -149,7 +169,12 @@ public: /// /// /// - optional family() const; + std::size_t family() const; + + /// + /// + /// + bool has_scheme() const; /// /// @@ -159,7 +184,7 @@ public: /// /// /// - optional scheme() const; + std::string scheme() const; /// /// Returns true if left is exactly equal to right. @@ -177,12 +202,12 @@ private: /// /// /// - std::string name_ = "Calibri"; + optional name_; /// /// /// - std::size_t size_ = 12; + optional size_; /// /// diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp index 634171f2..658638c9 100644 --- a/include/xlnt/styles/number_format.hpp +++ b/include/xlnt/styles/number_format.hpp @@ -196,17 +196,17 @@ public: /// /// /// - void set_format_string(const std::string &format_code); + void format_string(const std::string &format_code); /// /// /// - void set_format_string(const std::string &format_code, std::size_t custom_id); + void format_string(const std::string &format_code, std::size_t custom_id); /// /// /// - std::string get_format_string() const; + std::string format_string() const; /// /// @@ -216,12 +216,12 @@ public: /// /// /// - void set_id(std::size_t id); + void id(std::size_t id); /// /// /// - std::size_t get_id() const; + std::size_t id() const; /// /// diff --git a/include/xlnt/utils/datetime.hpp b/include/xlnt/utils/datetime.hpp index 2f54eedd..1c3cb68b 100644 --- a/include/xlnt/utils/datetime.hpp +++ b/include/xlnt/utils/datetime.hpp @@ -55,6 +55,11 @@ struct XLNT_API datetime /// static datetime from_number(long double number, calendar base_date); + /// + /// + /// + static datetime from_iso_string(const std::string &iso_string); + /// /// /// @@ -70,6 +75,11 @@ struct XLNT_API datetime /// std::string to_string() const; + /// + /// + /// + std::string to_iso_string() const; + /// /// /// diff --git a/include/xlnt/utils/exceptions.hpp b/include/xlnt/utils/exceptions.hpp index 24b3b1e2..adf0af90 100644 --- a/include/xlnt/utils/exceptions.hpp +++ b/include/xlnt/utils/exceptions.hpp @@ -55,7 +55,7 @@ public: /// /// /// - void set_message(const std::string &message); + void message(const std::string &message); private: /// diff --git a/include/xlnt/utils/path.hpp b/include/xlnt/utils/path.hpp index 8a18b91d..7ebafbe6 100644 --- a/include/xlnt/utils/path.hpp +++ b/include/xlnt/utils/path.hpp @@ -115,6 +115,13 @@ public: /// path resolve(const path &base_path) const; + /// + /// The inverse of path::resolve. Creates a relative path from an absolute + /// path by removing the common root between base_path and this path. + /// If the current path is already relative, return it unchanged. + /// + path relative_to(const path &base_path) const; + // filesystem attributes /// diff --git a/include/xlnt/workbook/named_range.hpp b/include/xlnt/workbook/named_range.hpp index faacc19a..6a60ca91 100644 --- a/include/xlnt/workbook/named_range.hpp +++ b/include/xlnt/workbook/named_range.hpp @@ -38,7 +38,7 @@ std::vector> XLNT_API split_named_range(cons /// /// A 2D range of cells in a worksheet that is referred to by name. -/// ws->get_range("A1:B2") could be replaced by ws->get_range("range1") +/// ws->range("A1:B2") could be replaced by ws->range("range1") /// class XLNT_API named_range { @@ -66,12 +66,12 @@ public: /// /// /// - std::string get_name() const; + std::string name() const; /// /// /// - const std::vector &get_targets() const; + const std::vector &targets() const; /// /// diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 29d83b1e..781359ac 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -150,31 +150,6 @@ public: /// ~workbook(); - // general properties - - /// - /// Returns true if guess_types is enabled for this workbook. - /// - bool get_guess_types() const; - - /// - /// Set to true to guess the type represented by a string set as the value - /// for a cell and then set the actual value of the cell to that type. - /// For example, cell.set_value("1") with guess_types enabled will set - /// type of the cell to numeric and it's value to the number 1. - /// - void set_guess_types(bool guess); - - /// - /// ? - /// - bool get_data_only() const; - - /// - /// ? - /// - void set_data_only(bool data_only); - // add worksheets /// @@ -209,41 +184,41 @@ public: /// This is also the sheet that will be shown when the workbook is opened /// in the spreadsheet editor program. /// - worksheet get_active_sheet(); + worksheet active_sheet(); /// /// Return the worksheet with the given name. /// This may throw an exception if the sheet isn't found. /// Use workbook::contains(const std::string &) to make sure the sheet exists. /// - worksheet get_sheet_by_title(const std::string &sheet_name); + worksheet sheet_by_title(const std::string &sheet_name); /// /// Return the const worksheet with the given name. /// This may throw an exception if the sheet isn't found. /// Use workbook::contains(const std::string &) to make sure the sheet exists. /// - const worksheet get_sheet_by_title(const std::string &sheet_name) const; + const worksheet sheet_by_title(const std::string &sheet_name) const; /// /// Return the worksheet at the given index. /// - worksheet get_sheet_by_index(std::size_t index); + worksheet sheet_by_index(std::size_t index); /// /// Return the const worksheet at the given index. /// - const worksheet get_sheet_by_index(std::size_t index) const; + const worksheet sheet_by_index(std::size_t index) const; /// /// Return the worksheet with a sheetId of id. /// - worksheet get_sheet_by_id(std::size_t id); + worksheet sheet_by_id(std::size_t id); /// /// Return the const worksheet with a sheetId of id. /// - const worksheet get_sheet_by_id(std::size_t id) const; + const worksheet sheet_by_id(std::size_t id) const; /// /// Return true if this workbook contains a sheet with the given name. @@ -254,7 +229,7 @@ public: /// Return the index of the given worksheet. /// The worksheet must be owned by this workbook. /// - std::size_t get_index(worksheet worksheet); + std::size_t index(worksheet worksheet); // remove worksheets @@ -317,159 +292,61 @@ public: /// Returns a temporary vector containing the titles of each sheet in the order /// of the sheets in the workbook. /// - std::vector get_sheet_titles() const; + std::vector sheet_titles() const; /// /// Returns the number of sheets in this workbook. /// - std::size_t get_sheet_count() const; + std::size_t sheet_count() const; - /// - /// Returns the name of the application that created this workbook. - /// - std::string get_application() const; - - /// - /// Sets the name of the application that created this workbook to "application". - /// - void set_application(const std::string &application); + /// + /// Returns true if the workbook has the core property with the given name. + /// + bool has_core_property(const std::string &property_name) const; /// /// /// - calendar get_base_date() const; + template + T core_property(const std::string &property_name) const; /// /// /// - void set_base_date(calendar base_date); + template + void core_property(const std::string &property_name, const T value); /// /// /// - std::string get_creator() const; + calendar base_date() const; /// /// /// - void set_creator(const std::string &creator); + void base_date(calendar base_date); /// /// /// - std::string get_last_modified_by() const; + bool has_title() const; /// /// /// - void set_last_modified_by(const std::string &last_modified_by); + std::string title() const; /// /// /// - datetime get_created() const; - - /// - /// - /// - void set_created(const datetime &when); - - /// - /// - /// - datetime get_modified() const; - - /// - /// - /// - void set_modified(const datetime &when); - - /// - /// - /// - int get_doc_security() const; - - /// - /// - /// - void set_doc_security(int doc_security); - - /// - /// - /// - bool get_scale_crop() const; - - /// - /// - /// - void set_scale_crop(bool scale_crop); - - /// - /// - /// - std::string get_company() const; - - /// - /// - /// - void set_company(const std::string &company); - - /// - /// - /// - bool links_up_to_date() const; - - /// - /// - /// - void set_links_up_to_date(bool links_up_to_date); - - /// - /// - /// - bool is_shared_doc() const; - - /// - /// - /// - void set_shared_doc(bool shared_doc); - - /// - /// - /// - bool hyperlinks_changed() const; - - /// - /// - /// - void set_hyperlinks_changed(bool hyperlinks_changed); - - /// - /// - /// - std::string get_app_version() const; - - /// - /// - /// - void set_app_version(const std::string &version); - - /// - /// - /// - std::string get_title() const; - - /// - /// - /// - void set_title(const std::string &title); + void title(const std::string &title); // named ranges /// /// /// - std::vector get_named_ranges() const; + std::vector named_ranges() const; /// /// @@ -489,7 +366,7 @@ public: /// /// /// - range get_named_range(const std::string &name); + range named_range(const std::string &name); /// /// @@ -608,12 +485,12 @@ public: /// /// /// - workbook_view get_view() const; + workbook_view view() const; /// /// /// - void set_view(const workbook_view &view); + void view(const workbook_view &view); /// /// @@ -623,52 +500,12 @@ public: /// /// /// - std::string get_code_name() const; + std::string code_name() const; /// /// /// - void set_code_name(const std::string &code_name); - - /// - /// - /// - bool x15_enabled() const; - - /// - /// - /// - void enable_x15(); - - /// - /// - /// - void disable_x15(); - - /// - /// - /// - bool has_absolute_path() const; - - /// - /// - /// - path get_absolute_path() const; - - /// - /// - /// - void set_absolute_path(const path &absolute_path); - - /// - /// - /// - void clear_absolute_path(); - - /// - /// - /// - bool has_properties() const; + void code_name(const std::string &code_name); /// /// @@ -678,34 +515,22 @@ public: /// /// /// - std::string get_app_name() const; + std::string app_name() const; /// /// /// - std::size_t get_last_edited() const; + std::size_t last_edited() const; /// /// /// - std::size_t get_lowest_edited() const; + std::size_t lowest_edited() const; /// /// /// - std::size_t get_rup_build() const; - - /// - /// - /// - bool has_arch_id() const; - - // calculation - - /// - /// - /// - bool has_calculation_properties() const; + std::size_t rup_build() const; // theme @@ -717,29 +542,29 @@ public: /// /// /// - const theme &get_theme() const; + const theme &theme() const; /// /// /// - void set_theme(const theme &value); + void theme(const class theme &value); // formats /// /// /// - format get_format(std::size_t format_index); + format format(std::size_t format_index); /// /// /// - const format get_format(std::size_t format_index) const; + const class format format(std::size_t format_index) const; /// /// /// - format create_format(bool default_format = false); + class format create_format(bool default_format = false); /// /// @@ -778,12 +603,12 @@ public: /// /// /// - manifest &get_manifest(); + manifest &manifest(); /// /// /// - const manifest &get_manifest() const; + const class manifest &manifest() const; // shared strings @@ -795,25 +620,25 @@ public: /// /// /// - std::vector &get_shared_strings(); + std::vector &shared_strings(); /// /// /// - const std::vector &get_shared_strings() const; + const std::vector &shared_strings() const; // thumbnail /// /// /// - void set_thumbnail(const std::vector &thumbnail, + void thumbnail(const std::vector &thumbnail, const std::string &extension, const std::string &content_type); /// /// /// - const std::vector &get_thumbnail() const; + const std::vector &thumbnail() const; // operators diff --git a/include/xlnt/worksheet/cell_vector.hpp b/include/xlnt/worksheet/cell_vector.hpp index fde19934..ecead1e2 100644 --- a/include/xlnt/worksheet/cell_vector.hpp +++ b/include/xlnt/worksheet/cell_vector.hpp @@ -71,11 +71,6 @@ public: /// cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row); - /// - /// - /// - std::size_t num_cells() const; - /// /// /// @@ -109,12 +104,12 @@ public: /// /// /// - cell get_cell(std::size_t column_index); + cell cell(std::size_t column_index); /// /// /// - const cell get_cell(std::size_t column_index) const; + const class cell cell(std::size_t column_index) const; /// /// diff --git a/include/xlnt/worksheet/footer.hpp b/include/xlnt/worksheet/footer.hpp index cf3e5275..1b8df3ec 100644 --- a/include/xlnt/worksheet/footer.hpp +++ b/include/xlnt/worksheet/footer.hpp @@ -44,22 +44,22 @@ public: /// /// /// - void set_text(const std::string &text); + void text(const std::string &text); /// /// /// - void set_font_name(const std::string &font_name); + void font_name(const std::string &font_name); /// /// /// - void set_font_size(std::size_t font_size); + void font_size(std::size_t font_size); /// /// /// - void set_font_color(const std::string &font_color); + void font_color(const std::string &font_color); /// /// diff --git a/include/xlnt/worksheet/header.hpp b/include/xlnt/worksheet/header.hpp index 63a9d094..29a8222c 100644 --- a/include/xlnt/worksheet/header.hpp +++ b/include/xlnt/worksheet/header.hpp @@ -44,22 +44,22 @@ public: /// /// /// - void set_text(const std::string &text); + void text(const std::string &text); /// /// /// - void set_font_name(const std::string &font_name); + void font_name(const std::string &font_name); /// /// /// - void set_font_size(std::size_t font_size); + void font_size(std::size_t font_size); /// /// /// - void set_font_color(const std::string &font_color); + void font_color(const std::string &font_color); /// /// diff --git a/include/xlnt/worksheet/header_footer.hpp b/include/xlnt/worksheet/header_footer.hpp index 1d067113..aaf88556 100644 --- a/include/xlnt/worksheet/header_footer.hpp +++ b/include/xlnt/worksheet/header_footer.hpp @@ -46,32 +46,32 @@ public: /// /// /// - header &get_left_header(); + header &left_header(); /// /// /// - header &get_center_header(); + header ¢er_header(); /// /// /// - header &get_right_header(); + header &right_header(); /// /// /// - footer &get_left_footer(); + footer &left_footer(); /// /// /// - footer &get_center_footer(); + footer ¢er_footer(); /// /// /// - footer &get_right_footer(); + footer &right_footer(); /// /// diff --git a/include/xlnt/worksheet/page_margins.hpp b/include/xlnt/worksheet/page_margins.hpp index 1c5e6c66..4a664e6f 100644 --- a/include/xlnt/worksheet/page_margins.hpp +++ b/include/xlnt/worksheet/page_margins.hpp @@ -41,62 +41,62 @@ public: /// /// /// - double get_top() const; + double top() const; /// /// /// - void set_top(double top); + void top(double top); /// /// /// - double get_left() const; + double left() const; /// /// /// - void set_left(double left); + void left(double left); /// /// /// - double get_bottom() const; + double bottom() const; /// /// /// - void set_bottom(double bottom); + void bottom(double bottom); /// /// /// - double get_right() const; + double right() const; /// /// /// - void set_right(double right); + void right(double right); /// /// /// - double get_header() const; + double header() const; /// /// /// - void set_header(double header); + void header(double header); /// /// /// - double get_footer() const; + double footer() const; /// /// /// - void set_footer(double footer); + void footer(double footer); private: /// diff --git a/include/xlnt/worksheet/page_setup.hpp b/include/xlnt/worksheet/page_setup.hpp index c1997606..362deb4a 100644 --- a/include/xlnt/worksheet/page_setup.hpp +++ b/include/xlnt/worksheet/page_setup.hpp @@ -45,42 +45,42 @@ public: /// /// /// - page_break get_break() const; + page_break page_break() const; /// /// /// - void set_break(page_break b); + void page_break(enum page_break b); /// /// /// - sheet_state get_sheet_state() const; + sheet_state sheet_state() const; /// /// /// - void set_sheet_state(sheet_state sheet_state); + void sheet_state(enum sheet_state sheet_state); /// /// /// - paper_size get_paper_size() const; + paper_size paper_size() const; /// /// /// - void set_paper_size(paper_size paper_size); + void paper_size(enum paper_size paper_size); /// /// /// - orientation get_orientation() const; + orientation orientation() const; /// /// /// - void set_orientation(orientation orientation); + void orientation(enum orientation orientation); /// /// @@ -90,7 +90,7 @@ public: /// /// /// - void set_fit_to_page(bool fit_to_page); + void fit_to_page(bool fit_to_page); /// /// @@ -100,7 +100,7 @@ public: /// /// /// - void set_fit_to_height(bool fit_to_height); + void fit_to_height(bool fit_to_height); /// /// @@ -110,58 +110,58 @@ public: /// /// /// - void set_fit_to_width(bool fit_to_width); + void fit_to_width(bool fit_to_width); /// /// /// - void set_horizontal_centered(bool horizontal_centered); + void horizontal_centered(bool horizontal_centered); /// /// /// - bool get_horizontal_centered() const; + bool horizontal_centered() const; /// /// /// - void set_vertical_centered(bool vertical_centered); + void vertical_centered(bool vertical_centered); /// /// /// - bool get_vertical_centered() const; + bool vertical_centered() const; /// /// /// - void set_scale(double scale); + void scale(double scale); /// /// /// - double get_scale() const; + double scale() const; private: /// /// /// - page_break break_; + enum page_break break_; /// /// /// - sheet_state sheet_state_; + enum sheet_state sheet_state_; /// /// /// - paper_size paper_size_; + enum paper_size paper_size_; /// /// /// - orientation orientation_; + enum orientation orientation_; /// /// diff --git a/include/xlnt/worksheet/pane.hpp b/include/xlnt/worksheet/pane.hpp index 4198fc0f..af590edc 100644 --- a/include/xlnt/worksheet/pane.hpp +++ b/include/xlnt/worksheet/pane.hpp @@ -35,7 +35,8 @@ namespace xlnt { enum class XLNT_API pane_state { frozen, - normal + frozen_split, + split }; /// @@ -52,33 +53,41 @@ enum class XLNT_API pane_corner /// /// A fixed portion of a worksheet. /// -class XLNT_API pane +struct XLNT_API pane { -public: /// /// /// - cell_reference top_left_cell; + optional top_left_cell; /// /// /// - pane_state state; + pane_state state = pane_state::split; /// /// /// - pane_corner active_pane; + pane_corner active_pane = pane_corner::top_left; /// /// /// - row_t y_split; + row_t y_split = 1; /// /// /// - column_t x_split; + column_t x_split = 1; + + bool operator==(const pane &rhs) const + { + return top_left_cell == rhs.top_left_cell + && state == rhs.state + && active_pane == rhs.active_pane + && y_split == rhs.y_split + && x_split == rhs.x_split; + } }; } // namespace xlnt diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index aa47c984..09c0508b 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -104,27 +104,27 @@ public: /// /// /// - cell_vector get_vector(std::size_t vector_index); + cell_vector vector(std::size_t vector_index); /// /// /// - const cell_vector get_vector(std::size_t vector_index) const; + const cell_vector vector(std::size_t vector_index) const; /// /// /// - cell get_cell(const cell_reference &ref); + cell cell(const cell_reference &ref); /// /// /// - const cell get_cell(const cell_reference &ref) const; + const class cell cell(const cell_reference &ref) const; /// /// /// - range_reference get_reference() const; + range_reference reference() const; /// /// diff --git a/include/xlnt/worksheet/range_reference.hpp b/include/xlnt/worksheet/range_reference.hpp index fa2f0f1c..1798a7c6 100644 --- a/include/xlnt/worksheet/range_reference.hpp +++ b/include/xlnt/worksheet/range_reference.hpp @@ -77,32 +77,32 @@ public: /// /// /// - std::size_t get_width() const; + std::size_t width() const; /// /// /// - std::size_t get_height() const; + std::size_t height() const; /// /// /// - cell_reference get_top_left() const; + cell_reference top_left() const; /// /// /// - cell_reference get_bottom_right() const; + cell_reference bottom_right() const; /// /// /// - cell_reference &get_top_left(); + cell_reference &top_left(); /// /// /// - cell_reference &get_bottom_right(); + cell_reference &bottom_right(); /// /// diff --git a/include/xlnt/worksheet/selection.hpp b/include/xlnt/worksheet/selection.hpp index ac4f3457..69d54785 100644 --- a/include/xlnt/worksheet/selection.hpp +++ b/include/xlnt/worksheet/selection.hpp @@ -38,38 +38,46 @@ public: /// /// /// - bool has_active_cell() const { return has_active_cell_; } + bool has_active_cell() const { return active_cell_.is_set(); } /// /// /// - cell_reference get_active_cell() const { return active_cell_; } + cell_reference active_cell() const { return active_cell_.get(); } /// /// /// - range_reference get_sqref() const { return sqref_; } + void active_cell(const cell_reference &ref) { active_cell_ = ref; } /// /// /// - pane_corner get_pane() const { return pane_; } + range_reference sqref() const { return sqref_; } /// /// /// - void set_pane(pane_corner corner) { pane_ = corner; } + pane_corner pane() const { return pane_; } + + /// + /// + /// + void pane(pane_corner corner) { pane_ = corner; } + + + bool operator==(const selection &rhs) const + { + return active_cell_ == rhs.active_cell_ + && sqref_ == rhs.sqref_ + && pane_ == rhs.pane_; + } private: /// /// /// - bool has_active_cell_ = false; - - /// - /// - /// - cell_reference active_cell_; + optional active_cell_; /// /// diff --git a/include/xlnt/worksheet/sheet_protection.hpp b/include/xlnt/worksheet/sheet_protection.hpp index 8788b75d..4531643d 100644 --- a/include/xlnt/worksheet/sheet_protection.hpp +++ b/include/xlnt/worksheet/sheet_protection.hpp @@ -43,12 +43,12 @@ public: /// /// /// - void set_password(const std::string &password); + void password(const std::string &password); /// /// /// - std::string get_hashed_password() const; + std::string hashed_password() const; private: /// diff --git a/include/xlnt/worksheet/sheet_view.hpp b/include/xlnt/worksheet/sheet_view.hpp index 862cb214..2bf421ae 100644 --- a/include/xlnt/worksheet/sheet_view.hpp +++ b/include/xlnt/worksheet/sheet_view.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include @@ -39,33 +40,117 @@ public: /// /// /// - pane &get_pane() { return pane_; } + void id(std::size_t new_id) { id_ = new_id; } /// /// /// - const pane &get_pane() const { return pane_; } + std::size_t id() const { return id_; } /// /// /// - std::vector &get_selections() { return selections_; } + bool has_pane() const { return pane_.is_set(); } /// /// /// - const std::vector &get_selections() const { return selections_; } + pane &pane() { return pane_.get(); } + + /// + /// + /// + const struct pane &pane() const { return pane_.get(); } + + /// + /// + /// + void clear_pane() { pane_.clear(); } + + /// + /// + /// + void pane(const struct pane &new_pane) { pane_ = new_pane; } + + /// + /// + /// + bool has_selections() const { return !selections_.empty(); } + + /// + /// + /// + void add_selection(const selection &new_selection) { selections_.push_back(new_selection); } + + /// + /// + /// + void clear_selections() { selections_.clear(); } + + /// + /// + /// + std::vector selections() const { return selections_; } + + /// + /// + /// + class selection &selection(std::size_t index) { return selections_.at(index); } + + /// + /// + /// + void show_grid_lines(bool show) { show_grid_lines_ = show; } + + /// + /// + /// + bool show_grid_lines() const { return show_grid_lines_; } + + /// + /// + /// + void default_grid_color(bool is_default) { default_grid_color_ = is_default; } + + /// + /// + /// + bool default_grid_color() const { return default_grid_color_; } + + bool operator==(const sheet_view &rhs) const + { + return id_ == rhs.id_ + && show_grid_lines_ == rhs.show_grid_lines_ + && default_grid_color_ == rhs.default_grid_color_ + && pane_ == rhs.pane_ + && selections_ == rhs.selections_; + } private: /// /// /// - pane pane_; + std::size_t id_ = 0; /// /// /// - std::vector selections_; + bool show_grid_lines_ = true; + + /// + /// + /// + bool default_grid_color_ = true; + + /// + /// + /// + optional pane_; + + /// + /// + /// + std::vector selections_; }; } // namespace xlnt diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 94b1674c..0366e308 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -109,12 +109,12 @@ public: /// /// /// - workbook &get_workbook(); + workbook &workbook(); /// /// /// - const workbook &get_workbook() const; + const class workbook &workbook() const; /// /// @@ -126,29 +126,29 @@ public: /// /// /// - std::size_t get_id() const; + std::size_t id() const; /// /// /// - void set_id(std::size_t id); + void id(std::size_t id); /// /// /// - std::string get_title() const; + std::string title() const; /// /// /// - void set_title(const std::string &title); + void title(const std::string &title); // freeze panes /// /// /// - cell_reference get_frozen_panes() const; + cell_reference frozen_panes() const; /// /// @@ -158,7 +158,7 @@ public: /// /// /// - void freeze_panes(const std::string &top_left_coordinate); + void freeze_panes(const cell_reference &top_left_coordinate); /// /// @@ -175,22 +175,22 @@ public: /// /// /// - cell get_cell(column_t column, row_t row); + cell cell(column_t column, row_t row); /// /// /// - const cell get_cell(column_t column, row_t row) const; + const class cell cell(column_t column, row_t row) const; /// /// /// - cell get_cell(const cell_reference &reference); + class cell cell(const cell_reference &reference); /// /// /// - const cell get_cell(const cell_reference &reference) const; + const class cell cell(const cell_reference &reference) const; /// /// @@ -200,59 +200,59 @@ public: /// /// /// - range get_range(const std::string &reference_string); + range range(const std::string &reference_string); /// /// /// - range get_range(const range_reference &reference); + class range range(const range_reference &reference); /// /// /// - const range get_range(const std::string &reference_string) const; + const class range range(const std::string &reference_string) const; /// /// /// - const range get_range(const range_reference &reference) const; + const class range range(const range_reference &reference) const; /// /// /// - range rows() const; + class range rows() const; /// /// /// - range rows(const std::string &range_string) const; + class range rows(const std::string &range_string) const; /// /// /// - range rows(int row_offset, int column_offset) const; + class range rows(int row_offset, int column_offset) const; /// /// /// - range rows(const std::string &range_string, int row_offset, int column_offset) const; + class range rows(const std::string &range_string, int row_offset, int column_offset) const; /// /// /// - range columns() const; + class range columns() const; // properties /// /// /// - column_properties &get_column_properties(column_t column); + column_properties &column_properties(column_t column); /// /// /// - const column_properties &get_column_properties(column_t column) const; + const class column_properties &column_properties(column_t column) const; /// /// @@ -262,17 +262,17 @@ public: /// /// /// - void add_column_properties(column_t column, const column_properties &props); + void add_column_properties(column_t column, const class column_properties &props); /// /// /// - row_properties &get_row_properties(row_t row); + row_properties &row_properties(row_t row); /// /// /// - const row_properties &get_row_properties(row_t row) const; + const class row_properties &row_properties(row_t row) const; /// /// @@ -282,19 +282,19 @@ public: /// /// /// - void add_row_properties(row_t row, const row_properties &props); + void add_row_properties(row_t row, const class row_properties &props); // positioning /// /// /// - cell_reference get_point_pos(int left, int top) const; + cell_reference point_pos(int left, int top) const; /// /// /// - cell_reference get_point_pos(const std::pair &point) const; + cell_reference point_pos(const std::pair &point) const; /// /// @@ -321,7 +321,7 @@ public: /// /// /// - range get_named_range(const std::string &name); + class range named_range(const std::string &name); /// /// @@ -333,27 +333,27 @@ public: /// /// /// - row_t get_lowest_row() const; + row_t lowest_row() const; /// /// /// - row_t get_highest_row() const; + row_t highest_row() const; /// /// /// - row_t get_next_row() const; + row_t next_row() const; /// /// /// - column_t get_lowest_column() const; + column_t lowest_column() const; /// /// /// - column_t get_highest_column() const; + column_t highest_column() const; /// /// @@ -400,7 +400,7 @@ public: /// /// /// - std::vector get_merged_ranges() const; + std::vector merged_ranges() const; // append @@ -464,42 +464,42 @@ public: /// /// /// - cell operator[](const cell_reference &reference); + class cell operator[](const cell_reference &reference); /// /// /// - const cell operator[](const cell_reference &reference) const; + const class cell operator[](const cell_reference &reference) const; /// /// /// - range operator[](const range_reference &reference); + class range operator[](const range_reference &reference); /// /// /// - const range operator[](const range_reference &reference) const; + const class range operator[](const range_reference &reference) const; /// /// /// - range operator[](const std::string &range_string); + class range operator[](const std::string &range_string); /// /// /// - const range operator[](const std::string &range_string) const; + const class range operator[](const std::string &range_string) const; /// /// /// - range operator()(const cell_reference &top_left, const cell_reference &bottom_right); + class range operator()(const cell_reference &top_left, const cell_reference &bottom_right); /// /// /// - const range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const; + const class range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const; /// /// @@ -516,12 +516,12 @@ public: /// /// /// - page_setup get_page_setup() const; + page_setup page_setup() const; /// /// /// - void set_page_setup(const page_setup &setup); + void page_setup(const struct page_setup &setup); /// /// @@ -531,12 +531,12 @@ public: /// /// /// - page_margins get_page_margins() const; + page_margins page_margins() const; /// /// /// - void set_page_margins(const page_margins &margins); + void page_margins(const class page_margins &margins); /// /// @@ -548,7 +548,7 @@ public: /// /// /// - range_reference get_auto_filter() const; + range_reference auto_filter() const; /// /// @@ -568,7 +568,7 @@ public: /// /// /// - void unset_auto_filter(); + void clear_auto_filter(); /// /// @@ -590,7 +590,7 @@ public: /// /// /// - std::size_t get_comment_count() const; + std::size_t comment_count() const; /// /// @@ -600,32 +600,32 @@ public: /// /// /// - header_footer &get_header_footer(); + header_footer &header_footer(); /// /// /// - const header_footer &get_header_footer() const; + const class header_footer &header_footer() const; /// /// /// - void set_parent(workbook &wb); + void parent(class workbook &wb); /// /// /// - std::vector get_formula_attributes() const; + std::vector formula_attributes() const; /// /// /// - sheet_state get_sheet_state() const; + sheet_state sheet_state() const; /// /// /// - void set_sheet_state(sheet_state state); + void sheet_state(enum sheet_state state); /// /// @@ -660,42 +660,42 @@ public: /// /// /// - range iter_cells(bool skip_null); + class range iter_cells(bool skip_null); /// /// /// - void set_print_title_rows(row_t first_row, row_t last_row); + void print_title_rows(row_t first_row, row_t last_row); /// /// /// - void set_print_title_rows(row_t last_row); + void print_title_rows(row_t last_row); /// /// /// - void set_print_title_cols(column_t first_column, column_t last_column); + void print_title_cols(column_t first_column, column_t last_column); /// /// /// - void set_print_title_cols(column_t last_column); + void print_title_cols(column_t last_column); /// /// /// - std::string get_print_titles() const; + std::string print_titles() const; /// /// /// - void set_print_area(const std::string &print_area); + void print_area(const std::string &print_area); /// /// /// - range_reference get_print_area() const; + range_reference print_area() const; /// /// @@ -705,22 +705,12 @@ public: /// /// /// - sheet_view get_view() const; + sheet_view view(std::size_t index = 0) const; /// /// /// - bool x14ac_enabled() const; - - /// - /// - /// - void enable_x14ac(); - - /// - /// - /// - void disable_x14ac(); + void add_view(const sheet_view &new_view); private: friend class cell; diff --git a/samples/sample.cpp b/samples/sample.cpp index f3edaa09..0f9023da 100644 --- a/samples/sample.cpp +++ b/samples/sample.cpp @@ -3,10 +3,10 @@ int main() { xlnt::workbook wb; - xlnt::worksheet ws = wb.get_active_sheet(); - ws.get_cell("A1").set_value(5); - ws.get_cell("B2").set_value("string data"); - ws.get_cell("C3").set_formula("=RAND()"); + xlnt::worksheet ws = wb.active_sheet(); + ws.cell("A1").value(5); + ws.cell("B2").value("string data"); + ws.cell("C3").formula("=RAND()"); ws.merge_cells("C3:C4"); ws.freeze_panes("B2"); wb.save("data/sample.xlsx"); diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index b2a4af9c..7a2725f4 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -193,73 +193,73 @@ cell::cell(detail::cell_impl *d) : d_(d) bool cell::garbage_collectible() const { - return !(get_data_type() != type::null || is_merged() || has_formula() || has_format()); + return !(data_type() != type::null || is_merged() || has_formula() || has_format()); } template <> -XLNT_API void cell::set_value(std::nullptr_t) +XLNT_API void cell::value(std::nullptr_t) { d_->type_ = type::null; } template <> -XLNT_API void cell::set_value(bool b) +XLNT_API void cell::value(bool b) { d_->value_numeric_ = b ? 1 : 0; d_->type_ = type::boolean; } template <> -XLNT_API void cell::set_value(std::int8_t i) +XLNT_API void cell::value(std::int8_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::int16_t i) +XLNT_API void cell::value(std::int16_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::int32_t i) +XLNT_API void cell::value(std::int32_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::int64_t i) +XLNT_API void cell::value(std::int64_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::uint8_t i) +XLNT_API void cell::value(std::uint8_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::uint16_t i) +XLNT_API void cell::value(std::uint16_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::uint32_t i) +XLNT_API void cell::value(std::uint32_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::uint64_t i) +XLNT_API void cell::value(std::uint64_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; @@ -267,7 +267,7 @@ XLNT_API void cell::set_value(std::uint64_t i) #ifdef _MSC_VER template <> -XLNT_API void cell::set_value(unsigned long i) +XLNT_API void cell::value(unsigned long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; @@ -276,14 +276,14 @@ XLNT_API void cell::set_value(unsigned long i) #ifdef __linux template <> -XLNT_API void cell::set_value(long long i) +XLNT_API void cell::value(long long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(unsigned long long i) +XLNT_API void cell::value(unsigned long long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; @@ -291,39 +291,39 @@ XLNT_API void cell::set_value(unsigned long long i) #endif template <> -XLNT_API void cell::set_value(float f) +XLNT_API void cell::value(float f) { d_->value_numeric_ = static_cast(f); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(double d) +XLNT_API void cell::value(double d) { d_->value_numeric_ = static_cast(d); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(long double d) +XLNT_API void cell::value(long double d) { d_->value_numeric_ = static_cast(d); d_->type_ = type::numeric; } template <> -XLNT_API void cell::set_value(std::string s) +XLNT_API void cell::value(std::string s) { s = check_string(s); if (s.size() > 1 && s.front() == '=') { d_->type_ = type::formula; - set_formula(s); + formula(s); } else if (cell::error_codes().find(s) != cell::error_codes().end()) { - set_error(s); + error(s); } else { @@ -332,39 +332,34 @@ XLNT_API void cell::set_value(std::string s) if (s.size() > 0) { - get_workbook().add_shared_string(d_->value_text_); + workbook().add_shared_string(d_->value_text_); } } - - if (get_workbook().get_guess_types()) - { - guess_type_and_set_value(s); - } } template <> -XLNT_API void cell::set_value(formatted_text text) +XLNT_API void cell::value(formatted_text text) { if (text.runs().size() == 1 && !text.runs().front().has_formatting()) { - set_value(text.plain_text()); + value(text.plain_text()); } else { d_->type_ = type::string; d_->value_text_ = text; - get_workbook().add_shared_string(text); + workbook().add_shared_string(text); } } template <> -XLNT_API void cell::set_value(char const *c) +XLNT_API void cell::value(char const *c) { - set_value(std::string(c)); + value(std::string(c)); } template <> -XLNT_API void cell::set_value(cell c) +XLNT_API void cell::value(cell c) { d_->type_ = c.d_->type_; d_->value_numeric_ = c.d_->value_numeric_; @@ -375,48 +370,48 @@ XLNT_API void cell::set_value(cell c) } template <> -XLNT_API void cell::set_value(date d) +XLNT_API void cell::value(date d) { d_->type_ = type::numeric; - d_->value_numeric_ = d.to_number(get_base_date()); - set_number_format(number_format::date_yyyymmdd2()); + d_->value_numeric_ = d.to_number(base_date()); + number_format(number_format::date_yyyymmdd2()); } template <> -XLNT_API void cell::set_value(datetime d) +XLNT_API void cell::value(datetime d) { d_->type_ = type::numeric; - d_->value_numeric_ = d.to_number(get_base_date()); - set_number_format(number_format::date_datetime()); + d_->value_numeric_ = d.to_number(base_date()); + number_format(number_format::date_datetime()); } template <> -XLNT_API void cell::set_value(time t) +XLNT_API void cell::value(time t) { d_->type_ = type::numeric; d_->value_numeric_ = t.to_number(); - set_number_format(number_format::date_time6()); + number_format(number_format::date_time6()); } template <> -XLNT_API void cell::set_value(timedelta t) +XLNT_API void cell::value(timedelta t) { d_->type_ = type::numeric; d_->value_numeric_ = t.to_number(); - set_number_format(number_format("[hh]:mm:ss")); + number_format(xlnt::number_format("[hh]:mm:ss")); } -row_t cell::get_row() const +row_t cell::row() const { return d_->row_; } -column_t cell::get_column() const +column_t cell::column() const { return d_->column_; } -void cell::set_merged(bool merged) +void cell::merged(bool merged) { d_->is_merged_ = merged; } @@ -428,10 +423,10 @@ bool cell::is_merged() const bool cell::is_date() const { - return get_data_type() == type::numeric && has_format() && get_number_format().is_date_format(); + return data_type() == type::numeric && has_format() && number_format().is_date_format(); } -cell_reference cell::get_reference() const +cell_reference cell::reference() const { return {d_->column_, d_->row_}; } @@ -464,15 +459,15 @@ cell &cell::operator=(const cell &rhs) std::string cell::to_repr() const { - return "parent_).get_title() + "." + get_reference().to_string() + ">"; + return ""; } -std::string cell::get_hyperlink() const +std::string cell::hyperlink() const { return d_->hyperlink_.get(); } -void cell::set_hyperlink(const std::string &hyperlink) +void cell::hyperlink(const std::string &hyperlink) { if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end()) { @@ -481,13 +476,13 @@ void cell::set_hyperlink(const std::string &hyperlink) d_->hyperlink_ = hyperlink; - if (get_data_type() == type::null) + if (data_type() == type::null) { - set_value(hyperlink); + value(hyperlink); } } -void cell::set_formula(const std::string &formula) +void cell::formula(const std::string &formula) { if (formula.empty()) { @@ -506,10 +501,10 @@ void cell::set_formula(const std::string &formula) bool cell::has_formula() const { - return d_->formula_; + return d_->formula_.is_set(); } -std::string cell::get_formula() const +std::string cell::formula() const { return d_->formula_.get(); } @@ -519,7 +514,7 @@ void cell::clear_formula() d_->formula_.clear(); } -void cell::set_error(const std::string &error) +void cell::error(const std::string &error) { if (error.length() == 0 || error[0] != '#') { @@ -532,31 +527,31 @@ void cell::set_error(const std::string &error) cell cell::offset(int column, int row) { - return get_worksheet().get_cell(get_reference().make_offset(column, row)); + return worksheet().cell(reference().make_offset(column, row)); } -worksheet cell::get_worksheet() +worksheet cell::worksheet() { - return worksheet(d_->parent_); + return xlnt::worksheet(d_->parent_); } -const worksheet cell::get_worksheet() const +const worksheet cell::worksheet() const { - return worksheet(d_->parent_); + return xlnt::worksheet(d_->parent_); } -workbook &cell::get_workbook() +workbook &cell::workbook() { - return get_worksheet().get_workbook(); + return worksheet().workbook(); } -const workbook &cell::get_workbook() const +const workbook &cell::workbook() const { - return get_worksheet().get_workbook(); + return worksheet().workbook(); } -// TODO: this shares a lot of code with worksheet::get_point_pos, try to reduce repetion -std::pair cell::get_anchor() const +// TODO: this shares a lot of code with worksheet::point_pos, try to reduce repetion +std::pair cell::anchor() const { static const auto DefaultColumnWidth = 51.85L; static const auto DefaultRowHeight = 15.0L; @@ -570,9 +565,9 @@ std::pair cell::get_anchor() const for (column_t column_index = 1; column_index <= left_columns; column_index++) { - if (get_worksheet().has_column_properties(column_index)) + if (worksheet().has_column_properties(column_index)) { - auto cdw = get_worksheet().get_column_properties(column_index).width; + auto cdw = worksheet().column_properties(column_index).width; if (cdw > 0) { @@ -590,9 +585,9 @@ std::pair cell::get_anchor() const for (row_t row_index = 1; row_index <= top_rows; row_index++) { - if (get_worksheet().has_row_properties(row_index)) + if (worksheet().has_row_properties(row_index)) { - auto rdh = get_worksheet().get_row_properties(row_index).height; + auto rdh = worksheet().row_properties(row_index).height; if (rdh > 0) { @@ -607,12 +602,12 @@ std::pair cell::get_anchor() const return {left_anchor, top_anchor}; } -cell::type cell::get_data_type() const +cell::type cell::data_type() const { return d_->type_; } -void cell::set_data_type(type t) +void cell::data_type(type t) { d_->type_ = t; } @@ -656,159 +651,159 @@ void cell::clear_value() } template <> -XLNT_API bool cell::get_value() const +XLNT_API bool cell::value() const { return d_->value_numeric_ != 0.L; } template <> -XLNT_API std::int8_t cell::get_value() const +XLNT_API std::int8_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::int16_t cell::get_value() const +XLNT_API std::int16_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::int32_t cell::get_value() const +XLNT_API std::int32_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::int64_t cell::get_value() const +XLNT_API std::int64_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::uint8_t cell::get_value() const +XLNT_API std::uint8_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::uint16_t cell::get_value() const +XLNT_API std::uint16_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::uint32_t cell::get_value() const +XLNT_API std::uint32_t cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API std::uint64_t cell::get_value() const +XLNT_API std::uint64_t cell::value() const { return static_cast(d_->value_numeric_); } #ifdef __linux template <> -XLNT_API long long cell::get_value() const +XLNT_API long long cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API unsigned long long cell::get_value() const +XLNT_API unsigned long long cell::value() const { return static_cast(d_->value_numeric_); } #endif template <> -XLNT_API float cell::get_value() const +XLNT_API float cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API double cell::get_value() const +XLNT_API double cell::value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_API long double cell::get_value() const +XLNT_API long double cell::value() const { return d_->value_numeric_; } template <> -XLNT_API time cell::get_value() const +XLNT_API time cell::value() const { return time::from_number(d_->value_numeric_); } template <> -XLNT_API datetime cell::get_value() const +XLNT_API datetime cell::value() const { - return datetime::from_number(d_->value_numeric_, get_base_date()); + return datetime::from_number(d_->value_numeric_, base_date()); } template <> -XLNT_API date cell::get_value() const +XLNT_API date cell::value() const { - return date::from_number(static_cast(d_->value_numeric_), get_base_date()); + return date::from_number(static_cast(d_->value_numeric_), base_date()); } template <> -XLNT_API timedelta cell::get_value() const +XLNT_API timedelta cell::value() const { return timedelta::from_number(d_->value_numeric_); } -void cell::set_alignment(const xlnt::alignment &alignment_) +void cell::alignment(const class alignment &alignment_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.alignment(alignment_, true)); } -void cell::set_border(const xlnt::border &border_) +void cell::border(const class border &border_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.border(border_, true)); } -void cell::set_fill(const xlnt::fill &fill_) +void cell::fill(const class fill &fill_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.fill(fill_, true)); } -void cell::set_font(const font &font_) +void cell::font(const class font &font_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.font(font_, true)); } -void cell::set_number_format(const number_format &number_format_) +void cell::number_format(const class number_format &number_format_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.number_format(number_format_, true)); } -void cell::set_protection(const xlnt::protection &protection_) +void cell::protection(const class protection &protection_) { - auto new_format = has_format() ? modifiable_format() : get_workbook().create_format(); + auto new_format = has_format() ? modifiable_format() : workbook().create_format(); format(new_format.protection(protection_, true)); } template <> -XLNT_API std::string cell::get_value() const +XLNT_API std::string cell::value() const { return d_->value_text_.plain_text(); } template <> -XLNT_API formatted_text cell::get_value() const +XLNT_API formatted_text cell::value() const { return d_->value_text_; } @@ -822,18 +817,18 @@ std::string cell::to_string() const { auto nf = computed_number_format(); - switch (get_data_type()) + switch (data_type()) { case cell::type::null: return ""; case cell::type::numeric: - return nf.format(get_value(), get_base_date()); + return nf.format(value(), base_date()); case cell::type::string: case cell::type::formula: case cell::type::error: - return nf.format(get_value()); + return nf.format(value()); case cell::type::boolean: - return get_value() == 0.L ? "FALSE" : "TRUE"; + return value() == 0.L ? "FALSE" : "TRUE"; #ifdef WIN32 default: throw xlnt::exception("unhandled"); @@ -857,9 +852,9 @@ void cell::format(const class format new_format) d_->format_ = new_format.d_; } -calendar cell::get_base_date() const +calendar cell::base_date() const { - return get_workbook().get_base_date(); + return workbook().base_date(); } XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell) @@ -867,29 +862,36 @@ XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell) return stream << cell.to_string(); } -void cell::guess_type_and_set_value(const std::string &value) +void cell::value(const std::string &value_string, bool infer_type) { - auto percentage = cast_percentage(value); + value(value_string); + + if (!infer_type) + { + return; + } + + auto percentage = cast_percentage(value_string); if (percentage.first) { d_->value_numeric_ = percentage.second; d_->type_ = cell::type::numeric; - set_number_format(xlnt::number_format::percentage()); + number_format(xlnt::number_format::percentage()); } else { - auto time = cast_time(value); + auto time = cast_time(value_string); if (time.first) { d_->type_ = cell::type::numeric; - set_number_format(number_format::date_time6()); + number_format(number_format::date_time6()); d_->value_numeric_ = time.second.to_number(); } else { - auto numeric = cast_numeric(value); + auto numeric = cast_numeric(value_string); if (numeric.first) { @@ -916,13 +918,13 @@ void cell::clear_style() void cell::style(const class style &new_style) { - auto new_format = has_format() ? format() : get_workbook().create_format(); + auto new_format = has_format() ? format() : workbook().create_format(); format(new_format.style(new_style)); } void cell::style(const std::string &style_name) { - style(get_workbook().style(style_name)); + style(workbook().style(style_name)); } const style cell::style() const @@ -960,32 +962,32 @@ const format cell::format() const return xlnt::format(*d_->format_); } -alignment cell::get_alignment() const +alignment cell::alignment() const { return format().alignment(); } -border cell::get_border() const +border cell::border() const { return format().border(); } -fill cell::get_fill() const +fill cell::fill() const { return format().fill(); } -font cell::get_font() const +font cell::font() const { return format().font(); } -number_format cell::get_number_format() const +number_format cell::number_format() const { return format().number_format(); } -protection cell::get_protection() const +protection cell::protection() const { return format().protection(); } @@ -1027,12 +1029,12 @@ void cell::comment(const class comment &new_comment) d_->comment_.set(new_comment); // offset comment 5 pixels down and 5 pixels right of the top right corner of the cell - auto cell_position = get_anchor(); + auto cell_position = anchor(); - // todo: make this cell_position.first += get_width() instead - if (get_worksheet().has_column_properties(get_column())) + // todo: make this cell_position.first += width() instead + if (worksheet().has_column_properties(column())) { - cell_position.first += static_cast(get_worksheet().get_column_properties(get_column()).width); + cell_position.first += static_cast(worksheet().column_properties(column()).width); } else { @@ -1052,7 +1054,7 @@ void cell::comment(const class comment &new_comment) d_->comment_.get().position(cell_position.first, cell_position.second); d_->comment_.get().size(200, 100); - get_worksheet().register_comments_in_manifest(); + worksheet().register_comments_in_manifest(); } } // namespace xlnt diff --git a/source/cell/cell_reference.cpp b/source/cell/cell_reference.cpp index 7b727339..459931c8 100644 --- a/source/cell/cell_reference.cpp +++ b/source/cell/cell_reference.cpp @@ -33,7 +33,7 @@ namespace xlnt { std::size_t cell_reference_hash::operator()(const cell_reference &k) const { - return k.get_row() * constants::max_column().index + k.get_column_index().index; + return k.row() * constants::max_column().index + k.column_index(); } cell_reference &cell_reference::make_absolute(bool absolute_column, bool absolute_row) @@ -52,8 +52,8 @@ cell_reference::cell_reference(const std::string &string) { auto split = split_reference(string, absolute_column_, absolute_row_); - set_column(split.first); - set_row(split.second); + column(split.first); + row(split.second); } cell_reference::cell_reference(const char *reference_string) @@ -205,32 +205,32 @@ void cell_reference::row_absolute(bool absolute_row) absolute_row_ = absolute_row; } -column_t cell_reference::get_column() const +column_t cell_reference::column() const { return column_; } -void cell_reference::set_column(const std::string &column_string) +void cell_reference::column(const std::string &column_string) { column_ = column_t(column_string); } -column_t cell_reference::get_column_index() const +column_t::index_t cell_reference::column_index() const { - return column_; + return column_.index; } -void cell_reference::set_column_index(column_t column) +void cell_reference::column_index(column_t column) { column_ = column; } -row_t cell_reference::get_row() const +row_t cell_reference::row() const { return row_; } -void cell_reference::set_row(row_t row) +void cell_reference::row(row_t row) { row_ = row; } diff --git a/source/cell/formatted_text.cpp b/source/cell/formatted_text.cpp index b81e71e7..f3bc47cc 100644 --- a/source/cell/formatted_text.cpp +++ b/source/cell/formatted_text.cpp @@ -42,7 +42,7 @@ void formatted_text::plain_text(const std::string &s) std::string formatted_text::plain_text() const { return std::accumulate(runs_.begin(), runs_.end(), std::string(), - [](const std::string &a, const text_run &run) { return a + run.get_string(); }); + [](const std::string &a, const text_run &run) { return a + run.string(); }); } std::vector formatted_text::runs() const @@ -61,42 +61,42 @@ bool formatted_text::operator==(const formatted_text &rhs) const for (std::size_t i = 0; i < runs_.size(); i++) { - if (runs_[i].get_string() != rhs.runs_[i].get_string()) return false; + if (runs_[i].string() != rhs.runs_[i].string()) return false; if (runs_[i].has_formatting() != rhs.runs_[i].has_formatting()) return false; if (runs_[i].has_formatting()) { if (runs_[i].has_color() != rhs.runs_[i].has_color() || (runs_[i].has_color() - && runs_[i].get_color() != rhs.runs_[i].get_color())) + && runs_[i].color() != rhs.runs_[i].color())) { return false; } if (runs_[i].has_family() != rhs.runs_[i].has_family() || (runs_[i].has_family() - && runs_[i].get_family() != rhs.runs_[i].get_family())) + && runs_[i].family() != rhs.runs_[i].family())) { return false; } if (runs_[i].has_font() != rhs.runs_[i].has_font() || (runs_[i].has_font() - && runs_[i].get_font() != rhs.runs_[i].get_font())) + && runs_[i].font() != rhs.runs_[i].font())) { return false; } if (runs_[i].has_scheme() != rhs.runs_[i].has_scheme() || (runs_[i].has_scheme() - && runs_[i].get_scheme() != rhs.runs_[i].get_scheme())) + && runs_[i].scheme() != rhs.runs_[i].scheme())) { return false; } if (runs_[i].has_size() != rhs.runs_[i].has_size() || (runs_[i].has_size() - && runs_[i].get_size() != rhs.runs_[i].get_size())) + && runs_[i].size() != rhs.runs_[i].size())) { return false; } diff --git a/source/cell/tests/test_cell.hpp b/source/cell/tests/test_cell.hpp index 3fd3308b..b45918bc 100644 --- a/source/cell/tests/test_cell.hpp +++ b/source/cell/tests/test_cell.hpp @@ -25,74 +25,70 @@ int random(int min, int max) class test_cell : public CxxTest::TestSuite { -private: - xlnt::workbook wb, wb_guess_types; - public: - test_cell() - { - wb_guess_types.set_guess_types(true); - } - void test_infer_numeric() { - auto ws = wb_guess_types.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); - cell.set_value("4.2"); - TS_ASSERT(cell.get_value() == 4.2L); + cell.value("4.2", true); + TS_ASSERT(cell.value() == 4.2L); - cell.set_value("-42.000"); - TS_ASSERT(cell.get_value() == -42); + cell.value("-42.000", true); + TS_ASSERT(cell.value() == -42); - cell.set_value("0"); - TS_ASSERT(cell.get_value() == 0); + cell.value("0", true); + TS_ASSERT(cell.value() == 0); - cell.set_value("0.9999"); - TS_ASSERT(cell.get_value() == 0.9999L); + cell.value("0.9999", true); + TS_ASSERT(cell.value() == 0.9999L); - cell.set_value("99E-02"); - TS_ASSERT(cell.get_value() == 0.99L); + cell.value("99E-02", true); + TS_ASSERT(cell.value() == 0.99L); - cell.set_value("4"); - TS_ASSERT(cell.get_value() == 4); + cell.value("4", true); + TS_ASSERT(cell.value() == 4); - cell.set_value("-1E3"); - TS_ASSERT(cell.get_value() == -1000); + cell.value("-1E3", true); + TS_ASSERT(cell.value() == -1000); - cell.set_value("2e+2"); - TS_ASSERT(cell.get_value() == 200); + cell.value("2e+2", true); + TS_ASSERT(cell.value() == 200); - cell.set_value("3.1%"); - TS_ASSERT(cell.get_value() == 0.031L); + cell.value("3.1%", true); + TS_ASSERT(cell.value() == 0.031L); - cell.set_value("03:40:16"); - TS_ASSERT(cell.get_value() == xlnt::time(3, 40, 16)); + cell.value("03:40:16", true); + TS_ASSERT(cell.value() == xlnt::time(3, 40, 16)); - cell.set_value("03:"); - TS_ASSERT_EQUALS(cell.get_value(), "03:"); + cell.value("03:", true); + TS_ASSERT_EQUALS(cell.value(), "03:"); - cell.set_value("03:40"); - TS_ASSERT(cell.get_value() == xlnt::time(3, 40)); + cell.value("03:40", true); + TS_ASSERT(cell.value() == xlnt::time(3, 40)); - cell.set_value("30:33.865633336"); - TS_ASSERT(cell.get_value() == xlnt::time(0, 30, 33, 865633)); + cell.value("30:33.865633336", true); + TS_ASSERT(cell.value() == xlnt::time(0, 30, 33, 865633)); } void test_ctor() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference("A", 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference("A", 1)); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null); - TS_ASSERT(cell.get_column() == "A"); - TS_ASSERT(cell.get_row() == 1); - TS_ASSERT(cell.get_reference() == "A1"); + TS_ASSERT(cell.data_type() == xlnt::cell::type::null); + TS_ASSERT(cell.column() == "A"); + TS_ASSERT(cell.row() == 1); + TS_ASSERT(cell.reference() == "A1"); TS_ASSERT(!cell.has_value()); } void test_null() { + xlnt::workbook wb; + const auto datatypes = { xlnt::cell::type::null, @@ -105,60 +101,64 @@ public: for(const auto &datatype : datatypes) { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_data_type(datatype); - TS_ASSERT(cell.get_data_type() == datatype); + cell.data_type(datatype); + TS_ASSERT(cell.data_type() == datatype); cell.clear_value(); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null); + TS_ASSERT(cell.data_type() == xlnt::cell::type::null); } } void test_string() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value("hello"); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string); + cell.value("hello"); + TS_ASSERT(cell.data_type() == xlnt::cell::type::string); - cell.set_value("."); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string); + cell.value("."); + TS_ASSERT(cell.data_type() == xlnt::cell::type::string); - cell.set_value("0800"); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string); + cell.value("0800"); + TS_ASSERT(cell.data_type() == xlnt::cell::type::string); } void test_formula1() { - auto ws = wb_guess_types.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value("=42"); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula); + cell.value("=42", true); + TS_ASSERT(cell.data_type() == xlnt::cell::type::formula); } void test_formula2() { - auto ws = wb_guess_types.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value("=if(A1<4;-1;1)"); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula); + cell.value("=if(A1<4;-1;1)", true); + TS_ASSERT(cell.data_type() == xlnt::cell::type::formula); } void test_formula3() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); TS_ASSERT(!cell.has_formula()); - TS_ASSERT_THROWS(cell.set_formula(""), xlnt::invalid_parameter); - TS_ASSERT_THROWS(cell.get_formula(), xlnt::invalid_attribute); - cell.set_formula("=42"); + TS_ASSERT_THROWS(cell.formula(""), xlnt::invalid_parameter); + TS_ASSERT(!cell.has_formula()); + cell.formula("=42"); TS_ASSERT(cell.has_formula()); - TS_ASSERT_EQUALS(cell.get_formula(), "42"); + TS_ASSERT_EQUALS(cell.formula(), "42"); cell.clear_formula(); TS_ASSERT(!cell.has_formula()); } @@ -166,81 +166,88 @@ public: void test_not_formula() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value("="); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string); - TS_ASSERT(cell.get_value() == "="); + cell.value("="); + TS_ASSERT(cell.data_type() == xlnt::cell::type::string); + TS_ASSERT(cell.value() == "="); TS_ASSERT(!cell.has_formula()); } void test_boolean() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); for(auto value : {true, false}) { - cell.set_value(value); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::boolean); + cell.value(value); + TS_ASSERT(cell.data_type() == xlnt::cell::type::boolean); } } void test_error_codes() { - auto ws = wb_guess_types.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); for(auto error_code : xlnt::cell::error_codes()) { - cell.set_value(error_code.first); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::error); + cell.value(error_code.first, true); + TS_ASSERT(cell.data_type() == xlnt::cell::type::error); } } void test_insert_datetime() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::datetime(2010, 7, 13, 6, 37, 41)); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric); - TS_ASSERT(cell.get_value() == 40372.27616898148L); + cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41)); + TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric); + TS_ASSERT(cell.value() == 40372.27616898148L); TS_ASSERT(cell.is_date()); - TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd h:mm:ss"); + TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss"); } void test_insert_date() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::date(2010, 7, 13)); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric); - TS_ASSERT(cell.get_value() == 40372.L); + cell.value(xlnt::date(2010, 7, 13)); + TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric); + TS_ASSERT(cell.value() == 40372.L); TS_ASSERT(cell.is_date()); - TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd"); + TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd"); } void test_insert_time() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::time(1, 3)); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric); - TS_ASSERT(cell.get_value() == 0.04375L); + cell.value(xlnt::time(1, 3)); + TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric); + TS_ASSERT(cell.value() == 0.04375L); TS_ASSERT(cell.is_date()); - TS_ASSERT(cell.get_number_format().get_format_string() == "h:mm:ss"); + TS_ASSERT(cell.number_format().format_string() == "h:mm:ss"); } void test_cell_formatted_as_date1() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::datetime::today()); + cell.value(xlnt::datetime::today()); cell.clear_value(); TS_ASSERT(!cell.is_date()); // disagree with openpyxl TS_ASSERT(!cell.has_value()); @@ -248,30 +255,33 @@ public: void test_cell_formatted_as_date2() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::datetime::today()); - cell.set_value("testme"); + cell.value(xlnt::datetime::today()); + cell.value("testme"); TS_ASSERT(!cell.is_date()); - TS_ASSERT(cell.get_value() == "testme"); + TS_ASSERT(cell.value() == "testme"); } void test_cell_formatted_as_date3() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::datetime::today()); - cell.set_value(true); + cell.value(xlnt::datetime::today()); + cell.value(true); TS_ASSERT(!cell.is_date()); - TS_ASSERT(cell.get_value() == true); + TS_ASSERT(cell.value() == true); } void test_illegal_characters() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); // The bytes 0x00 through 0x1F inclusive must be manually escaped in values. auto illegal_chrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; @@ -279,130 +289,138 @@ public: for(auto i : illegal_chrs) { std::string str(1, i); - TS_ASSERT_THROWS(cell.set_value(str), xlnt::illegal_character); + TS_ASSERT_THROWS(cell.value(str), xlnt::illegal_character); } - cell.set_value(std::string(1, 33)); - cell.set_value(std::string(1, 9)); // Tab - cell.set_value(std::string(1, 10)); // Newline - cell.set_value(std::string(1, 13)); // Carriage return - cell.set_value(" Leading and trailing spaces are legal "); + cell.value(std::string(1, 33)); + cell.value(std::string(1, 9)); // Tab + cell.value(std::string(1, 10)); // Newline + cell.value(std::string(1, 13)); // Carriage return + cell.value(" Leading and trailing spaces are legal "); } // void test_time_regex() {} void test_timedelta() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - cell.set_value(xlnt::timedelta(1, 3, 0, 0, 0)); + cell.value(xlnt::timedelta(1, 3, 0, 0, 0)); - TS_ASSERT(cell.get_value() == 1.125); - TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric); + TS_ASSERT(cell.value() == 1.125); + TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric); TS_ASSERT(!cell.is_date()); - TS_ASSERT(cell.get_number_format().get_format_string() == "[hh]:mm:ss"); + TS_ASSERT(cell.number_format().format_string() == "[hh]:mm:ss"); } void test_repr() { - auto ws = wb[1]; - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); - TS_ASSERT(cell.to_repr() == ""); + TS_ASSERT(cell.to_repr() == ""); } void test_cell_offset() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); - TS_ASSERT(cell.offset(1, 2).get_reference() == "B3"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); + TS_ASSERT(cell.offset(1, 2).reference() == "B3"); } void test_font() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); auto font = xlnt::font().bold(true); - cell.set_font(font); + cell.font(font); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().font_applied()); - TS_ASSERT_EQUALS(cell.get_font(), font); + TS_ASSERT_EQUALS(cell.font(), font); } void test_fill() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); xlnt::fill fill(xlnt::pattern_fill() .type(xlnt::pattern_fill_type::solid) .foreground(xlnt::color::red())); - cell.set_fill(fill); + cell.fill(fill); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().fill_applied()); - TS_ASSERT_EQUALS(cell.get_fill(), fill); + TS_ASSERT_EQUALS(cell.fill(), fill); } void test_border() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); xlnt::border border; - - cell.set_border(border); + cell.border(border); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().border_applied()); - TS_ASSERT_EQUALS(cell.get_border(), border); + TS_ASSERT_EQUALS(cell.border(), border); } void test_number_format() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); xlnt::number_format format("dd--hh--mm"); - cell.set_number_format(format); + cell.number_format(format); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().number_format_applied()); - TS_ASSERT_EQUALS(cell.get_number_format().get_format_string(), "dd--hh--mm"); + TS_ASSERT_EQUALS(cell.number_format().format_string(), "dd--hh--mm"); } void test_alignment() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); xlnt::alignment align; align.wrap(true); - cell.set_alignment(align); + cell.alignment(align); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().alignment_applied()); - TS_ASSERT_EQUALS(cell.get_alignment(), align); + TS_ASSERT_EQUALS(cell.alignment(), align); } void test_protection() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); TS_ASSERT(!cell.has_format()); auto protection = xlnt::protection().locked(false).hidden(true); - cell.set_protection(protection); + cell.protection(protection); TS_ASSERT(cell.has_format()); TS_ASSERT(cell.format().protection_applied()); - TS_ASSERT_EQUALS(cell.get_protection(), protection); + TS_ASSERT_EQUALS(cell.protection(), protection); TS_ASSERT(cell.has_format()); cell.clear_format(); @@ -411,8 +429,9 @@ public: void test_style() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); TS_ASSERT(!cell.has_style()); @@ -448,10 +467,11 @@ public: void test_print() { - auto ws = wb.create_sheet(); + xlnt::workbook wb; + auto ws = wb.active_sheet(); { - auto cell = ws.get_cell("A1"); + auto cell = ws.cell("A1"); std::stringstream ss; ss << cell; @@ -463,9 +483,9 @@ public: } { - auto cell = ws.get_cell("A2"); + auto cell = ws.cell("A2"); - cell.set_value(false); + cell.value(false); std::stringstream ss; ss << cell; @@ -477,9 +497,9 @@ public: } { - auto cell = ws.get_cell("A3"); + auto cell = ws.cell("A3"); - cell.set_value(true); + cell.value(true); std::stringstream ss; ss << cell; @@ -491,9 +511,9 @@ public: } { - auto cell = ws.get_cell("A4"); + auto cell = ws.cell("A4"); - cell.set_value(1.234); + cell.value(1.234); std::stringstream ss; ss << cell; @@ -505,9 +525,9 @@ public: } { - auto cell = ws.get_cell("A5"); + auto cell = ws.cell("A5"); - cell.set_error("#REF"); + cell.error("#REF"); std::stringstream ss; ss << cell; @@ -519,9 +539,9 @@ public: } { - auto cell = ws.get_cell("A6"); + auto cell = ws.cell("A6"); - cell.set_value("test"); + cell.value("test"); std::stringstream ss; ss << cell; @@ -535,57 +555,58 @@ public: void test_values() { - auto ws = wb.create_sheet(); - auto cell = ws.get_cell("A1"); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); - cell.set_value(static_cast(4)); - TS_ASSERT_EQUALS(cell.get_value(), 4); + cell.value(static_cast(4)); + TS_ASSERT_EQUALS(cell.value(), 4); - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); - cell.set_value(static_cast(4)); - TS_ASSERT_EQUALS(cell.get_value(), 4); + cell.value(static_cast(4)); + TS_ASSERT_EQUALS(cell.value(), 4); - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); - cell.set_value(static_cast(4)); - TS_ASSERT_EQUALS(cell.get_value(), 4); + cell.value(static_cast(4)); + TS_ASSERT_EQUALS(cell.value(), 4); - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); - cell.set_value(static_cast(4)); - TS_ASSERT_EQUALS(cell.get_value(), 4); + cell.value(static_cast(4)); + TS_ASSERT_EQUALS(cell.value(), 4); - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); #ifdef __linux - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); #endif - cell.set_value(static_cast(3)); - TS_ASSERT_EQUALS(cell.get_value(), 3); + cell.value(static_cast(3)); + TS_ASSERT_EQUALS(cell.value(), 3); - cell.set_value(static_cast(3.14)); - TS_ASSERT_DELTA(cell.get_value(), 3.14, 0.001); + cell.value(static_cast(3.14)); + TS_ASSERT_DELTA(cell.value(), 3.14, 0.001); - cell.set_value(static_cast(4.1415)); - TS_ASSERT_EQUALS(cell.get_value(), 4.1415); + cell.value(static_cast(4.1415)); + TS_ASSERT_EQUALS(cell.value(), 4.1415); - cell.set_value(static_cast(3.141592)); - TS_ASSERT_EQUALS(cell.get_value(), 3.141592); + cell.value(static_cast(3.141592)); + TS_ASSERT_EQUALS(cell.value(), 3.141592); - auto cell2 = ws.get_cell("A2"); - cell2.set_value(std::string(100'000, 'a')); - cell.set_value(cell2); - TS_ASSERT_EQUALS(cell.get_value(), std::string(32'767, 'a')); + auto cell2 = ws.cell("A2"); + cell2.value(std::string(100'000, 'a')); + cell.value(cell2); + TS_ASSERT_EQUALS(cell.value(), std::string(32'767, 'a')); } void test_reference() @@ -610,8 +631,8 @@ public: void test_anchor() { xlnt::workbook wb; - auto cell = wb.get_active_sheet().get_cell("A1"); - auto anchor = cell.get_anchor(); + auto cell = wb.active_sheet().cell("A1"); + auto anchor = cell.anchor(); TS_ASSERT_EQUALS(anchor.first, 0); TS_ASSERT_EQUALS(anchor.second, 0); } @@ -619,28 +640,28 @@ public: void test_hyperlink() { xlnt::workbook wb; - auto cell = wb.get_active_sheet().get_cell("A1"); + auto cell = wb.active_sheet().cell("A1"); TS_ASSERT(!cell.has_hyperlink()); - TS_ASSERT_THROWS(cell.get_hyperlink(), xlnt::invalid_attribute); - TS_ASSERT_THROWS(cell.set_hyperlink("notaurl"), xlnt::invalid_parameter); - TS_ASSERT_THROWS(cell.set_hyperlink(""), xlnt::invalid_parameter); - cell.set_hyperlink("http://example.com"); + TS_ASSERT_THROWS(cell.hyperlink(), xlnt::invalid_attribute); + TS_ASSERT_THROWS(cell.hyperlink("notaurl"), xlnt::invalid_parameter); + TS_ASSERT_THROWS(cell.hyperlink(""), xlnt::invalid_parameter); + cell.hyperlink("http://example.com"); TS_ASSERT(cell.has_hyperlink()); - TS_ASSERT_EQUALS(cell.get_hyperlink(), "http://example.com"); + TS_ASSERT_EQUALS(cell.hyperlink(), "http://example.com"); } void test_comment() { - xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - auto cell = ws.get_cell("A1"); - TS_ASSERT(!cell.has_comment()); - TS_ASSERT_THROWS(cell.comment(), xlnt::exception); - cell.comment(xlnt::comment("comment", "author")); - TS_ASSERT(cell.has_comment()); - TS_ASSERT_EQUALS(cell.comment(), xlnt::comment("comment", "author")); - cell.clear_comment(); - TS_ASSERT(!cell.has_comment()); - TS_ASSERT_THROWS(cell.comment(), xlnt::exception); + xlnt::workbook wb; + auto ws = wb.active_sheet(); + auto cell = ws.cell("A1"); + TS_ASSERT(!cell.has_comment()); + TS_ASSERT_THROWS(cell.comment(), xlnt::exception); + cell.comment(xlnt::comment("comment", "author")); + TS_ASSERT(cell.has_comment()); + TS_ASSERT_EQUALS(cell.comment(), xlnt::comment("comment", "author")); + cell.clear_comment(); + TS_ASSERT(!cell.has_comment()); + TS_ASSERT_THROWS(cell.comment(), xlnt::exception); } }; diff --git a/source/cell/tests/test_text.hpp b/source/cell/tests/test_text.hpp index 10b2c672..455fc156 100644 --- a/source/cell/tests/test_text.hpp +++ b/source/cell/tests/test_text.hpp @@ -22,41 +22,41 @@ public: TS_ASSERT_EQUALS(text1, text2); xlnt::text_run run_formatted; - run_formatted.set_color(xlnt::color::green()); - run_formatted.set_font("Cambria"); - run_formatted.set_scheme("ascheme"); - run_formatted.set_size(40); - run_formatted.set_family(17); + run_formatted.color(xlnt::color::green()); + run_formatted.font("Cambria"); + run_formatted.scheme("ascheme"); + run_formatted.size(40); + run_formatted.family(17); xlnt::formatted_text text_formatted; text_formatted.add_run(run_formatted); xlnt::text_run run_color_differs = run_formatted; - run_color_differs.set_color(xlnt::color::red()); + run_color_differs.color(xlnt::color::red()); xlnt::formatted_text text_color_differs; text_color_differs.add_run(run_color_differs); TS_ASSERT_DIFFERS(text_formatted, text_color_differs); xlnt::text_run run_font_differs = run_formatted; - run_font_differs.set_font("Calibri"); + run_font_differs.font("Calibri"); xlnt::formatted_text text_font_differs; text_font_differs.add_run(run_font_differs); TS_ASSERT_DIFFERS(text_formatted, text_font_differs); xlnt::text_run run_scheme_differs = run_formatted; - run_scheme_differs.set_scheme("bscheme"); + run_scheme_differs.scheme("bscheme"); xlnt::formatted_text text_scheme_differs; text_scheme_differs.add_run(run_scheme_differs); TS_ASSERT_DIFFERS(text_formatted, text_scheme_differs); xlnt::text_run run_size_differs = run_formatted; - run_size_differs.set_size(41); + run_size_differs.size(41); xlnt::formatted_text text_size_differs; text_size_differs.add_run(run_size_differs); TS_ASSERT_DIFFERS(text_formatted, text_size_differs); xlnt::text_run run_family_differs = run_formatted; - run_family_differs.set_family(18); + run_family_differs.family(18); xlnt::formatted_text text_family_differs; text_family_differs.add_run(run_family_differs); TS_ASSERT_DIFFERS(text_formatted, text_family_differs); diff --git a/source/cell/text_run.cpp b/source/cell/text_run.cpp index 6e8e96cb..4461ab4c 100644 --- a/source/cell/text_run.cpp +++ b/source/cell/text_run.cpp @@ -34,109 +34,144 @@ text_run::text_run(const std::string &string) : string_(string) { } -std::string text_run::get_string() const +std::string text_run::string() const { return string_; } -void text_run::set_string(const std::string &string) +void text_run::string(const std::string &string) { string_ = string; } bool text_run::has_formatting() const { - return has_size() || has_color() || has_font() || has_family() || has_scheme(); + return font_.is_set(); } bool text_run::has_size() const { - return size_.is_set(); + return font_.is_set() && font_.get().has_size(); } -std::size_t text_run::get_size() const +std::size_t text_run::size() const { - return *size_; + return font_.get().size(); } -void text_run::set_size(std::size_t size) +void text_run::size(std::size_t size) { - size_ = size; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().size(size); } bool text_run::has_color() const { - return color_.is_set(); + return font_.is_set() && font_.get().has_color(); } -color text_run::get_color() const +color text_run::color() const { - return *color_; + return font_.get().color(); } -void text_run::set_color(const color &new_color) +void text_run::color(const class color &new_color) { - color_ = new_color; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().color(new_color); } bool text_run::has_font() const { - return font_.is_set(); + return font_.is_set() && font_.get().has_name(); } -std::string text_run::get_font() const +std::string text_run::font() const { - return *font_; + return font_.get().name(); } -void text_run::set_font(const std::string &font) +void text_run::font(const std::string &font) { - font_ = font; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().name(font); } bool text_run::has_family() const { - return family_.is_set(); + return font_.is_set() && font_.get().has_family(); } -std::size_t text_run::get_family() const +std::size_t text_run::family() const { - return *family_; + return font_.get().family(); } -void text_run::set_family(std::size_t family) +void text_run::family(std::size_t family) { - family_ = family; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().family(family); } bool text_run::has_scheme() const { - return scheme_.is_set(); + return font_.is_set() && font_.get().has_scheme(); } -std::string text_run::get_scheme() const +std::string text_run::scheme() const { - return *scheme_; + return font_.get().scheme(); } -void text_run::set_scheme(const std::string &scheme) +void text_run::scheme(const std::string &scheme) { - scheme_ = scheme; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().scheme(scheme); } -bool text_run::bold_set() const +bool text_run::bold() const { - return bold_.is_set(); + return font_.is_set() && font_.get().bold(); } -bool text_run::is_bold() const +void text_run::bold(bool bold) { - return *bold_; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().bold(bold); } -void text_run::set_bold(bool bold) +void text_run::underline(font::underline_style style) { - bold_ = bold; + if (!font_.is_set()) + { + font_ = xlnt::font(); + } + + font_.get().underline(style); } } // namespace xlnt diff --git a/source/detail/constants.cpp b/source/detail/constants.cpp index 01789f41..70421bf6 100644 --- a/source/detail/constants.cpp +++ b/source/detail/constants.cpp @@ -65,7 +65,7 @@ const path constants::part_styles() { return package_xl().append("styles.xml"); const path constants::part_theme() { return package_theme().append("theme1.xml"); } const path constants::part_shared_strings() { return package_xl().append("sharedStrings.xml"); } -const std::unordered_map &constants::get_namespaces() +const std::unordered_map &constants::namespaces() { static const std::unordered_map *namespaces = new std::unordered_map @@ -77,6 +77,7 @@ const std::unordered_map &constants::get_namespaces() { "workbook", "http://schemas.openxmlformats.org/spreadsheetml/2006/main" }, { "core-properties", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties" }, { "extended-properties", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" }, + { "custom-properties", "http://schemas.openxmlformats.org/officeDocument/2006/customProperties" }, { "encryption", "http://schemas.microsoft.com/office/2006/encryption" }, { "encryption-password", "http://schemas.microsoft.com/office/2006/keyEncryptor/password" }, @@ -103,11 +104,11 @@ const std::unordered_map &constants::get_namespaces() return *namespaces; } -const std::string &constants::get_namespace(const std::string &id) +const std::string &constants::namespace_(const std::string &id) { - auto match = get_namespaces().find(id); + auto match = namespaces().find(id); - if (match == get_namespaces().end()) + if (match == namespaces().end()) { throw xlnt::exception("bad namespace"); } diff --git a/source/detail/constants.hpp b/source/detail/constants.hpp index 5af66821..96dae867 100644 --- a/source/detail/constants.hpp +++ b/source/detail/constants.hpp @@ -125,12 +125,12 @@ struct XLNT_API constants /// /// Returns an unordered_map mapping namespace names to namespaces. /// - static const std::unordered_map &get_namespaces(); + static const std::unordered_map &namespaces(); /// /// Returns the namespace URI from a namespace name. /// - static const std::string &get_namespace(const std::string &id); + static const std::string &namespace_(const std::string &id); }; } // namespace xlnt diff --git a/source/detail/custom_value_traits.cpp b/source/detail/custom_value_traits.cpp index 3e9836bb..7f72a46f 100644 --- a/source/detail/custom_value_traits.cpp +++ b/source/detail/custom_value_traits.cpp @@ -25,80 +25,80 @@ std::string to_string(font::underline_style style) /// /// Returns the string representation of the relationship type. /// -std::string to_string(relationship::type t) +std::string to_string(relationship_type t) { switch (t) { - case relationship::type::office_document: + case relationship_type::office_document: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; - case relationship::type::thumbnail: + case relationship_type::thumbnail: return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; - case relationship::type::calculation_chain: + case relationship_type::calculation_chain: return "http://purl.oclc.org/ooxml/officeDocument/relationships/calcChain"; - case relationship::type::extended_properties: + case relationship_type::extended_properties: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"; - case relationship::type::core_properties: + case relationship_type::core_properties: return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"; - case relationship::type::worksheet: + case relationship_type::worksheet: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"; - case relationship::type::shared_string_table: + case relationship_type::shared_string_table: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"; - case relationship::type::stylesheet: + case relationship_type::stylesheet: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; - case relationship::type::theme: + case relationship_type::theme: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"; - case relationship::type::hyperlink: + case relationship_type::hyperlink: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"; - case relationship::type::chartsheet: + case relationship_type::chartsheet: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet"; - case relationship::type::comments: + case relationship_type::comments: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"; - case relationship::type::vml_drawing: + case relationship_type::vml_drawing: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"; - case relationship::type::unknown: + case relationship_type::unknown: return "unknown"; - case relationship::type::custom_properties: + case relationship_type::custom_properties: return "custom-properties"; - case relationship::type::printer_settings: + case relationship_type::printer_settings: return "printer-settings"; - case relationship::type::connections: + case relationship_type::connections: return "connections"; - case relationship::type::custom_property: + case relationship_type::custom_property: return "custom-property"; - case relationship::type::custom_xml_mappings: + case relationship_type::custom_xml_mappings: return "custom-xml-mappings"; - case relationship::type::dialogsheet: + case relationship_type::dialogsheet: return "dialogsheet"; - case relationship::type::drawings: + case relationship_type::drawings: return "drawings"; - case relationship::type::external_workbook_references: + case relationship_type::external_workbook_references: return "external-workbook-references"; - case relationship::type::metadata: + case relationship_type::metadata: return "metadata"; - case relationship::type::pivot_table: + case relationship_type::pivot_table: return "pivot-table"; - case relationship::type::pivot_table_cache_definition: + case relationship_type::pivot_table_cache_definition: return "pivot-table-cache-definition"; - case relationship::type::pivot_table_cache_records: + case relationship_type::pivot_table_cache_records: return "pivot-table-cache-records"; - case relationship::type::query_table: + case relationship_type::query_table: return "query-table"; - case relationship::type::shared_workbook_revision_headers: + case relationship_type::shared_workbook_revision_headers: return "shared-workbook-revision-headers"; - case relationship::type::shared_workbook: + case relationship_type::shared_workbook: return "shared-workbook"; - case relationship::type::revision_log: + case relationship_type::revision_log: return "revision-log"; - case relationship::type::shared_workbook_user_data: + case relationship_type::shared_workbook_user_data: return "shared-workbook-user-data"; - case relationship::type::single_cell_table_definitions: + case relationship_type::single_cell_table_definitions: return "single-cell-table-definitions"; - case relationship::type::table_definition: + case relationship_type::table_definition: return "table-definition"; - case relationship::type::volatile_dependencies: + case relationship_type::volatile_dependencies: return "volatile-dependencies"; - case relationship::type::image: - return "image"; + case relationship_type::image: + return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"; #ifdef WIN32 default: throw xlnt::exception("unhandled"); diff --git a/source/detail/custom_value_traits.hpp b/source/detail/custom_value_traits.hpp index 9765b2c0..397c32f7 100644 --- a/source/detail/custom_value_traits.hpp +++ b/source/detail/custom_value_traits.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace xlnt { namespace detail { @@ -30,7 +31,7 @@ std::string to_string(font::underline_style underline_style); /// /// Returns the string representation of the relationship type. /// -std::string to_string(relationship::type t); +std::string to_string(relationship_type t); std::string to_string(pattern_fill_type fill_type); @@ -382,6 +383,52 @@ struct value_traits } }; // struct value_traits +template <> +struct value_traits +{ + static xlnt::pane_state parse(std::string string, const parser &) + { + if (string == "frozen") return xlnt::pane_state::frozen; + else if (string == "frozenSplit") return xlnt::pane_state::frozen_split; + else if (string == "split") return xlnt::pane_state::split; + return xlnt::pane_state::split; + } + + static std::string serialize (xlnt::pane_state state, const serializer &) + { + switch (state) + { + case xlnt::pane_state::frozen: return "frozen"; + case xlnt::pane_state::frozen_split: return "frozenSplit"; + case xlnt::pane_state::split: return "split"; + } + } +}; // struct value_traits + +template <> +struct value_traits +{ + static xlnt::pane_corner parse(std::string string, const parser &) + { + if (string == "bottomLeft") return xlnt::pane_corner::bottom_left; + else if (string == "bottomRight") return xlnt::pane_corner::bottom_right; + else if (string == "topLeft") return xlnt::pane_corner::top_left; + else if (string == "topRight") return xlnt::pane_corner::top_right; + return xlnt::pane_corner::top_left; + } + + static std::string serialize (xlnt::pane_corner corner, const serializer &) + { + switch (corner) + { + case xlnt::pane_corner::bottom_left: return "bottomLeft"; + case xlnt::pane_corner::bottom_right: return "bottomRight"; + case xlnt::pane_corner::top_left: return "topLeft"; + case xlnt::pane_corner::top_right: return "topRight"; + } + } +}; // struct value_traits + } diff --git a/source/detail/number_formatter.cpp b/source/detail/number_formatter.cpp index b539163f..d4786d92 100644 --- a/source/detail/number_formatter.cpp +++ b/source/detail/number_formatter.cpp @@ -191,7 +191,7 @@ number_format_parser::number_format_parser(const std::string &format_string) reset(format_string); } -const std::vector &number_format_parser::get_result() const +const std::vector &number_format_parser::result() const { return codes_; } @@ -1153,7 +1153,7 @@ number_formatter::number_formatter(const std::string &format_string, xlnt::calen calendar_(calendar) { parser_.parse(); - format_ = parser_.get_result(); + format_ = parser_.result(); } std::string number_formatter::format_number(long double number) diff --git a/source/detail/number_formatter.hpp b/source/detail/number_formatter.hpp index 863c9864..12574504 100644 --- a/source/detail/number_formatter.hpp +++ b/source/detail/number_formatter.hpp @@ -331,7 +331,7 @@ class number_format_parser { public: number_format_parser(const std::string &format_string); - const std::vector &get_result() const; + const std::vector &result() const; void reset(const std::string &format_string); void parse(); diff --git a/source/detail/stylesheet.hpp b/source/detail/stylesheet.hpp index 95e9dc5d..e9516b05 100644 --- a/source/detail/stylesheet.hpp +++ b/source/detail/stylesheet.hpp @@ -57,14 +57,14 @@ struct stylesheet impl.references = default_format ? 1 : 0; - return format(&impl); + return xlnt::format(&impl); } - format get_format(std::size_t index) + format format(std::size_t index) { auto iter = format_impls.begin(); std::advance(iter, static_cast::difference_type>(index)); - return format(&*iter); + return xlnt::format(&*iter); } class style create_style(const std::string &name) @@ -100,9 +100,9 @@ struct stylesheet for (const auto &nf : number_formats) { - if (nf.get_id() >= id) + if (nf.id() >= id) { - id = nf.get_id() + 1; + id = nf.id() + 1; } } diff --git a/source/detail/workbook_impl.hpp b/source/detail/workbook_impl.hpp index 092f4f6b..3a6c81ef 100644 --- a/source/detail/workbook_impl.hpp +++ b/source/detail/workbook_impl.hpp @@ -44,32 +44,7 @@ struct worksheet_impl; struct workbook_impl { - workbook_impl() - : active_sheet_index_(0), - guess_types_(false), - data_only_(false), - has_theme_(false), - write_core_properties_(false), - created_(xlnt::datetime::now()), - modified_(xlnt::datetime::now()), - base_date_(calendar::windows_1900), - write_app_properties_(false), - application_("libxlnt"), - doc_security_(0), - scale_crop_(false), - links_up_to_date_(false), - shared_doc_(false), - hyperlinks_changed_(false), - app_version_("0.9"), - x15_(false), - has_properties_(false), - has_absolute_path_(false), - has_view_(false), - has_code_name_(false), - has_file_version_(false), - has_calculation_properties_(false), - has_arch_id_(false), - short_bools_(true) + workbook_impl() : active_sheet_index_(0) { } @@ -77,46 +52,12 @@ struct workbook_impl : active_sheet_index_(other.active_sheet_index_), worksheets_(other.worksheets_), shared_strings_(other.shared_strings_), - guess_types_(other.guess_types_), - data_only_(other.data_only_), stylesheet_(other.stylesheet_), manifest_(other.manifest_), - has_theme_(other.has_theme_), theme_(other.theme_), - write_core_properties_(other.write_core_properties_), - creator_(other.creator_), - last_modified_by_(other.last_modified_by_), - created_(other.created_), - modified_(other.modified_), - title_(other.title_), - subject_(other.subject_), - description_(other.description_), - keywords_(other.keywords_), - category_(other.category_), - company_(other.company_), - base_date_(other.base_date_), - write_app_properties_(other.write_app_properties_), - application_(other.application_), - doc_security_(other.doc_security_), - scale_crop_(other.scale_crop_), - links_up_to_date_(other.links_up_to_date_), - shared_doc_(other.shared_doc_), - hyperlinks_changed_(other.hyperlinks_changed_), - app_version_(other.app_version_), - sheet_title_rel_id_map_(other.sheet_title_rel_id_map_), - x15_(other.x15_), - has_properties_(other.has_properties_), - has_absolute_path_(other.has_absolute_path_), - absolute_path_(other.absolute_path_), - has_view_(other.has_view_), view_(other.view_), - has_code_name_(other.has_code_name_), code_name_(other.code_name_), - has_file_version_(other.has_file_version_), - file_version_(other.file_version_), - has_calculation_properties_(other.has_calculation_properties_), - has_arch_id_(other.has_arch_id_), - short_bools_(other.short_bools_) + file_version_(other.file_version_) { } @@ -127,120 +68,49 @@ struct workbook_impl std::copy(other.worksheets_.begin(), other.worksheets_.end(), back_inserter(worksheets_)); shared_strings_.clear(); std::copy(other.shared_strings_.begin(), other.shared_strings_.end(), std::back_inserter(shared_strings_)); - guess_types_ = other.guess_types_; - data_only_ = other.data_only_; - has_theme_ = other.has_theme_; theme_ = other.theme_; manifest_ = other.manifest_; - write_core_properties_ = other.write_core_properties_; - creator_ = other.creator_; - last_modified_by_ = other.last_modified_by_; - created_ = other.created_; - modified_ = other.modified_; - title_ = other.title_; - subject_ = other.subject_; - description_ = other.description_; - keywords_ = other.keywords_; - category_ = other.category_; - company_ = other.company_; - base_date_ = other.base_date_; - - write_app_properties_ = other.write_app_properties_; - application_ = other.application_; - doc_security_ = other.doc_security_; - scale_crop_ = other.scale_crop_; - links_up_to_date_ = other.links_up_to_date_; - shared_doc_ = other.shared_doc_; - hyperlinks_changed_ = other.hyperlinks_changed_; - app_version_ = other.app_version_; - sheet_title_rel_id_map_ = other.sheet_title_rel_id_map_; - - x15_ = other.x15_; - has_properties_ = other.has_properties_; - has_absolute_path_ = other.has_absolute_path_; - absolute_path_ = other.absolute_path_; - has_view_ = other.has_view_; view_ = other.view_; - has_code_name_ = other.has_code_name_; code_name_ = other.code_name_; - - has_file_version_ = other.has_file_version_; file_version_ = other.file_version_; - has_calculation_properties_ = other.has_calculation_properties_; - has_arch_id_ = other.has_arch_id_; - - short_bools_ = other.short_bools_; - return *this; } - std::size_t active_sheet_index_; + optional active_sheet_index_; + std::list worksheets_; std::vector shared_strings_; - bool guess_types_; - bool data_only_; + optional stylesheet_; - stylesheet stylesheet_; + calendar base_date_; + optional title_; manifest manifest_; - bool has_theme_; - theme theme_; - std::vector thumbnail_; + optional theme_; + std::unordered_map> images_; - // core properties - - bool write_core_properties_; - std::string creator_; - std::string last_modified_by_; - datetime created_; - datetime modified_; - std::string title_; - std::string subject_; - std::string description_; - std::string keywords_; - std::string category_; - std::string company_; - calendar base_date_; - - // application properties - - bool write_app_properties_; - std::string application_; - int doc_security_; - bool scale_crop_; - bool links_up_to_date_; - bool shared_doc_; - bool hyperlinks_changed_; - std::string app_version_; + std::unordered_map core_properties_; + std::unordered_map extended_properties_; + std::unordered_map custom_properties_; std::unordered_map sheet_title_rel_id_map_; - bool x15_; - bool has_properties_; - bool has_absolute_path_; - path absolute_path_; - bool has_view_; - workbook_view view_; - bool has_code_name_; - std::string code_name_; + optional view_; + optional code_name_; - bool has_file_version_; struct file_version_t { std::string app_name; std::size_t last_edited; std::size_t lowest_edited; std::size_t rup_build; - } file_version_; - - bool has_calculation_properties_; - bool has_arch_id_; - - bool short_bools_; + }; + + optional file_version_; }; } // namespace detail diff --git a/source/detail/worksheet_impl.hpp b/source/detail/worksheet_impl.hpp index 6d8a4477..c0fe2401 100644 --- a/source/detail/worksheet_impl.hpp +++ b/source/detail/worksheet_impl.hpp @@ -84,8 +84,7 @@ struct worksheet_impl print_title_cols_ = other.print_title_cols_; print_title_rows_ = other.print_title_rows_; print_area_ = other.print_area_; - view_ = other.view_; - x14ac_ = other.x14ac_; + views_ = other.views_; has_dimension_ = other.has_dimension_; has_format_properties_ = other.has_format_properties_; } @@ -109,9 +108,7 @@ struct worksheet_impl std::string print_title_cols_; std::string print_title_rows_; range_reference print_area_; - bool has_view_ = false; - sheet_view view_; - bool x14ac_ = false; + std::vector views_; bool has_dimension_ = false; bool has_format_properties_ = false; }; diff --git a/source/detail/xlsx_consumer.cpp b/source/detail/xlsx_consumer.cpp index b12721a6..969cec6a 100644 --- a/source/detail/xlsx_consumer.cpp +++ b/source/detail/xlsx_consumer.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -88,28 +89,6 @@ bool is_true(const std::string &bool_string) #endif } -/// -/// Returns a datetime object representing the date and time in the ISO 8601-formatted string. -/// -xlnt::datetime w3cdtf_to_datetime(const std::string &string) -{ - xlnt::datetime result(1900, 1, 1); - - auto separator_index = string.find('-'); - result.year = std::stoi(string.substr(0, separator_index)); - result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1))); - separator_index = string.find('-', separator_index + 1); - result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1))); - separator_index = string.find('T', separator_index + 1); - result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); - separator_index = string.find(':', separator_index + 1); - result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); - separator_index = string.find(':', separator_index + 1); - result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1))); - - return result; -} - /// /// Helper template function that returns true if element is in container. /// @@ -143,16 +122,21 @@ xml::parser &xlsx_consumer::parser() std::vector xlsx_consumer::read_relationships(const path &part) { - std::vector relationships; - if (!archive_->has_file(part.string())) return relationships; + auto part_rels_path = part.parent() + .append("_rels") + .append(part.filename() + ".rels") + .relative_to(path("/")); - auto &rels_stream = archive_->open(part.string()); - xml::parser parser(rels_stream, part.string()); + std::vector relationships; + if (!archive_->has_file(part_rels_path.string())) return relationships; + + auto &rels_stream = archive_->open(part_rels_path.string()); + xml::parser parser(rels_stream, part_rels_path.string()); parser_ = &parser; xlnt::uri source(part.string()); - static const auto &xmlns = xlnt::constants::get_namespace("relationships"); + static const auto &xmlns = xlnt::constants::namespace_("relationships"); expect_start_element(xml::qname(xmlns, "Relationships"), xml::content::complex); @@ -160,13 +144,17 @@ std::vector xlsx_consumer::read_relationships(const path &part) { expect_start_element(xml::qname(xmlns, "Relationship"), xml::content::simple); - auto mode = parser.attribute_present("TargetMode") - ? parser.attribute("TargetMode") - : target_mode::internal; + auto target_mode = target_mode::internal; + + if (parser.attribute_present("TargetMode")) + { + target_mode = parser.attribute("TargetMode"); + } + relationships.emplace_back(parser.attribute("Id"), - parser.attribute("Type"), source, + parser.attribute("Type"), source, xlnt::uri(parser.attribute("Target")), - mode); + target_mode); expect_end_element(xml::qname(xmlns, "Relationship")); } @@ -182,151 +170,153 @@ std::vector xlsx_consumer::read_relationships(const path &part) void xlsx_consumer::read_part(const std::vector &rel_chain) { // ignore namespace declarations except in parts of these types - const auto using_namespaces = std::vector + const auto using_namespaces = std::vector { - relationship::type::office_document, - relationship::type::stylesheet, - relationship::type::chartsheet, - relationship::type::dialogsheet, - relationship::type::worksheet + relationship_type::office_document, + relationship_type::stylesheet, + relationship_type::chartsheet, + relationship_type::dialogsheet, + relationship_type::worksheet }; auto receive = xml::parser::receive_default; - if (contains(using_namespaces, rel_chain.back().get_type())) + if (contains(using_namespaces, rel_chain.back().type())) { receive |= xml::parser::receive_namespace_decls; } - const auto &manifest = target_.get_manifest(); + const auto &manifest = target_.manifest(); auto part_path = manifest.canonicalize(rel_chain); auto &stream = archive_->open(part_path.string()); xml::parser parser(stream, part_path.string(), receive); parser_ = &parser; - switch (rel_chain.back().get_type()) + switch (rel_chain.back().type()) { - case relationship::type::core_properties: - read_core_properties(); + case relationship_type::core_properties: + read_properties(part_path, xml::qname(constants::namespace_("core-properties"), "coreProperties")); break; - case relationship::type::extended_properties: - read_extended_properties(); + case relationship_type::extended_properties: + read_properties(part_path, xml::qname(constants::namespace_("extended-properties"), "Properties")); break; - case relationship::type::custom_properties: - read_custom_property(); + case relationship_type::custom_properties: + read_properties(part_path, xml::qname(constants::namespace_("custom-properties"), "Properties")); break; - case relationship::type::office_document: - read_workbook(); + case relationship_type::office_document: + read_office_document(manifest.content_type(part_path)); break; - case relationship::type::connections: + case relationship_type::connections: read_connections(); break; - case relationship::type::custom_xml_mappings: + case relationship_type::custom_xml_mappings: read_custom_xml_mappings(); break; - case relationship::type::external_workbook_references: + case relationship_type::external_workbook_references: read_external_workbook_references(); break; - case relationship::type::metadata: + case relationship_type::metadata: read_metadata(); break; - case relationship::type::pivot_table: + case relationship_type::pivot_table: read_pivot_table(); break; - case relationship::type::shared_workbook_revision_headers: + case relationship_type::shared_workbook_revision_headers: read_shared_workbook_revision_headers(); break; - case relationship::type::volatile_dependencies: + case relationship_type::volatile_dependencies: read_volatile_dependencies(); break; - case relationship::type::shared_string_table: + case relationship_type::shared_string_table: read_shared_string_table(); break; - case relationship::type::stylesheet: + case relationship_type::stylesheet: read_stylesheet(); break; - case relationship::type::theme: + case relationship_type::theme: read_theme(); break; - case relationship::type::chartsheet: - read_chartsheet(rel_chain.back().get_id()); + case relationship_type::chartsheet: + read_chartsheet(rel_chain.back().id()); break; - case relationship::type::dialogsheet: - read_dialogsheet(rel_chain.back().get_id()); + case relationship_type::dialogsheet: + read_dialogsheet(rel_chain.back().id()); break; - case relationship::type::worksheet: - read_worksheet(rel_chain.back().get_id()); + case relationship_type::worksheet: + read_worksheet(rel_chain.back().id()); break; - case relationship::type::thumbnail: + case relationship_type::thumbnail: + read_image(part_path); break; - case relationship::type::calculation_chain: + case relationship_type::calculation_chain: read_calculation_chain(); break; - case relationship::type::hyperlink: + case relationship_type::hyperlink: break; - case relationship::type::comments: + case relationship_type::comments: break; - case relationship::type::vml_drawing: + case relationship_type::vml_drawing: break; - case relationship::type::unknown: + case relationship_type::unknown: break; - case relationship::type::printer_settings: + case relationship_type::printer_settings: break; - case relationship::type::custom_property: + case relationship_type::custom_property: break; - case relationship::type::drawings: + case relationship_type::drawings: break; - case relationship::type::pivot_table_cache_definition: + case relationship_type::pivot_table_cache_definition: break; - case relationship::type::pivot_table_cache_records: + case relationship_type::pivot_table_cache_records: break; - case relationship::type::query_table: + case relationship_type::query_table: break; - case relationship::type::shared_workbook: + case relationship_type::shared_workbook: break; - case relationship::type::revision_log: + case relationship_type::revision_log: break; - case relationship::type::shared_workbook_user_data: + case relationship_type::shared_workbook_user_data: break; - case relationship::type::single_cell_table_definitions: + case relationship_type::single_cell_table_definitions: break; - case relationship::type::table_definition: + case relationship_type::table_definition: break; - case relationship::type::image: + case relationship_type::image: + read_image(part_path); break; } @@ -337,85 +327,52 @@ void xlsx_consumer::populate_workbook() { target_.clear(); - read_manifest(); - auto &manifest = target_.get_manifest(); + read_content_types(); + const auto root_path = path("/"); - auto package_parts = std::vector + for (const auto &package_rel : read_relationships(root_path)) { - relationship::type::core_properties, - relationship::type::extended_properties, - relationship::type::custom_properties, - relationship::type::office_document, - relationship::type::connections, - relationship::type::custom_xml_mappings, - relationship::type::external_workbook_references, - relationship::type::metadata, - relationship::type::pivot_table, - relationship::type::shared_workbook_revision_headers, - relationship::type::volatile_dependencies - }; + manifest().register_relationship(uri(root_path.string()), + package_rel.type(), + package_rel.target(), + package_rel.target_mode(), + package_rel.id()); + } - auto root_path = path("/"); - - for (auto rel_type : package_parts) + for (auto package_rel : manifest().relationships(root_path)) { - if (manifest.has_relationship(root_path, rel_type)) + if (package_rel.type() == relationship_type::office_document) { - read_part({manifest.get_relationship(root_path, rel_type)}); + // Read the workbook after all the other package parts + continue; + } + + read_part({package_rel}); + } + + for (const auto &relationship_source_string : archive_->files()) + { + for (const auto &part_rel : read_relationships(path(relationship_source_string))) + { + manifest().register_relationship(part_rel.source(), + part_rel.type(), + part_rel.target(), + part_rel.target_mode(), + part_rel.id()); } } - const auto workbook_rel = manifest.get_relationship(root_path, relationship::type::office_document); - - const auto workbook_parts_first = std::vector - { - relationship::type::shared_string_table, - relationship::type::stylesheet, - relationship::type::theme - }; - - for (auto rel_type : workbook_parts_first) - { - if (manifest.has_relationship(workbook_rel.get_target().get_path(), rel_type)) - { - read_part({workbook_rel, manifest.get_relationship(workbook_rel.get_target().get_path(), rel_type)}); - } - } - - const auto workbook_parts_second = std::vector - { - relationship::type::worksheet, - relationship::type::chartsheet, - relationship::type::dialogsheet - }; - - for (auto rel_type : workbook_parts_second) - { - if (manifest.has_relationship(workbook_rel.get_target().get_path(), rel_type)) - { - for (auto rel : manifest.get_relationships(workbook_rel.get_target().get_path(), rel_type)) - { - read_part({workbook_rel, rel}); - } - } - } + const auto workbook_rel = manifest().relationship(root_path, relationship_type::office_document); + read_part({workbook_rel}); } // Package Parts -void xlsx_consumer::read_manifest() +void xlsx_consumer::read_content_types() { - path package_rels_path("_rels/.rels"); + auto &manifest = target_.manifest(); - if (!archive_->has_file(package_rels_path.string())) - { - throw invalid_file("missing package rels"); - } - - auto package_rels = read_relationships(package_rels_path); - auto &manifest = target_.get_manifest(); - - static const auto &xmlns = constants::get_namespace("content-types"); + static const auto &xmlns = constants::namespace_("content-types"); xml::parser parser(archive_->open("[Content_Types].xml"), "[Content_Types].xml"); parser_ = &parser; @@ -447,242 +404,47 @@ void xlsx_consumer::read_manifest() } expect_end_element(xml::qname(xmlns, "Types")); - - for (const auto &package_rel : package_rels) - { - if (package_rel.get_type() == relationship::type::office_document) - { - auto content_type = manifest.get_content_type(manifest.canonicalize({ package_rel })); - check_document_type(content_type); - } - - manifest.register_relationship(uri("/"), - package_rel.get_type(), - package_rel.get_target(), - package_rel.get_target_mode(), - package_rel.get_id()); - } - - for (const auto &relationship_source_string : archive_->files()) - { - auto relationship_source = path(relationship_source_string); - - if (relationship_source == path("_rels/.rels") || relationship_source.extension() != "rels") continue; - - path part(relationship_source.parent().parent()); - part = part.append(relationship_source.split_extension().first); - uri source(part.string()); - - path source_directory = part.parent(); - - auto part_rels = read_relationships(relationship_source); - - for (const auto &part_rel : part_rels) - { - path target_path(source_directory.append(part_rel.get_target().get_path())); - manifest.register_relationship(source, - part_rel.get_type(), - part_rel.get_target(), - part_rel.get_target_mode(), - part_rel.get_id()); - } - } } -void xlsx_consumer::read_extended_properties() +void xlsx_consumer::read_properties(const path &part, const xml::qname &root) { - static const auto &xmlns = constants::get_namespace("extended-properties"); - static const auto &xmlns_vt = constants::get_namespace("vt"); + auto content_type = manifest().content_type(part); - expect_start_element(xml::qname(xmlns, "Properties"), xml::parser::content_type::complex); + std::unordered_map properties; + expect_start_element(root, xml::content::complex); - while (in_element(xml::qname(xmlns, "Properties"))) + while (in_element(root)) { - auto current_property_element = expect_start_element(xml::content::mixed); - auto text = read_text(); + auto property_element = expect_start_element(xml::content::mixed); - if (current_property_element == xml::qname(xmlns, "Application")) + if (property_element.name() != "Property") { - target_.set_application(text); - } - else if (current_property_element == xml::qname(xmlns, "DocSecurity")) - { - target_.set_doc_security(std::stoi(text)); - } - else if (current_property_element == xml::qname(xmlns, "ScaleCrop")) - { - target_.set_scale_crop(is_true(text)); - } - else if (current_property_element == xml::qname(xmlns, "Company")) - { - target_.set_company(text); - } - else if (current_property_element == xml::qname(xmlns, "SharedDoc")) - { - target_.set_shared_doc(is_true(text)); - } - else if (current_property_element == xml::qname(xmlns, "HyperlinksChanged")) - { - target_.set_hyperlinks_changed(is_true(text)); - } - else if (current_property_element == xml::qname(xmlns, "AppVersion")) - { - target_.set_app_version(text); - } - else if (current_property_element == xml::qname(xmlns, "LinksUpToDate")) - { - target_.set_links_up_to_date(is_true(text)); - } - else if (current_property_element == xml::qname(xmlns, "Template")) - { - // ignore - } - else if (current_property_element == xml::qname(xmlns, "TotalTime")) - { - // ignore - } - else if (current_property_element == xml::qname(xmlns, "HeadingPairs")) - { - expect_start_element(xml::qname(xmlns_vt, "vector"), xml::content::complex); - - skip_attributes(std::vector{"size", "baseType"}); - - expect_start_element(xml::qname(xmlns_vt, "variant"), xml::content::complex); - expect_start_element(xml::qname(xmlns_vt, "lpstr"), xml::content::simple); - read_text(); // ignore - expect_end_element(xml::qname(xmlns_vt, "lpstr")); - expect_end_element(xml::qname(xmlns_vt, "variant")); - - expect_start_element(xml::qname(xmlns_vt, "variant"), xml::content::complex); - expect_start_element(xml::qname(xmlns_vt, "i4"), xml::content::simple); - read_text(); // ignore - expect_end_element(xml::qname(xmlns_vt, "i4")); - expect_end_element(xml::qname(xmlns_vt, "variant")); - - expect_end_element(xml::qname(xmlns_vt, "vector")); - read_text(); // ignore trailing whitespace - } - else if (current_property_element == xml::qname(xmlns, "TitlesOfParts")) - { - expect_start_element(xml::qname(xmlns_vt, "vector"), xml::content::complex); - - auto size = parser().attribute("size"); - parser().attribute("baseType"); - - for (auto i = std::size_t(0); i < size; ++i) - { - expect_start_element(xml::qname(xmlns_vt, "lpstr"), xml::content::simple); - read_text(); // ignore - expect_end_element(xml::qname(xmlns_vt, "lpstr")); - } - - expect_end_element(xml::qname(xmlns_vt, "vector")); - read_text(); // ignore trailing whitespace - } - else - { - unexpected_element(current_property_element); - } - - expect_end_element(current_property_element); - } - - expect_end_element(xml::qname(xmlns, "Properties")); -} - -void xlsx_consumer::read_core_properties() -{ - static const auto &xmlns_cp = constants::get_namespace("core-properties"); - static const auto &xmlns_dc = constants::get_namespace("dc"); - static const auto &xmlns_dcterms = constants::get_namespace("dcterms"); - static const auto &xmlns_xsi = constants::get_namespace("xsi"); - - expect_start_element(xml::qname(xmlns_cp, "coreProperties"), xml::content::complex); - - while (in_element(xml::qname(xmlns_cp, "coreProperties"))) - { - auto property_element = expect_start_element(xml::content::simple); - auto property_value = std::string(); - - if (in_element(property_element)) - { - property_value = read_text(); - } - - if (property_element == xml::qname(xmlns_dc, "creator")) - { - target_.set_creator(property_value); - } - else if (property_element == xml::qname(xmlns_cp, "lastModifiedBy")) - { - target_.set_last_modified_by(property_value); - } - else if (property_element == xml::qname(xmlns_dcterms, "created")) - { - skip_attributes({xml::qname(xmlns_xsi, "type")}); - target_.set_created(w3cdtf_to_datetime(property_value)); - } - else if (property_element == xml::qname(xmlns_dcterms, "modified")) - { - skip_attributes({xml::qname(xmlns_xsi, "type")}); - target_.set_modified(w3cdtf_to_datetime(property_value)); - } - else if (property_element == xml::qname(xmlns_dc, "description")) - { - // ignore - } - else if (property_element == xml::qname(xmlns_dc, "language")) - { - // ignore - } - else if (property_element == xml::qname(xmlns_dc, "subject")) - { - // ignore - } - else if (property_element == xml::qname(xmlns_dc, "title")) - { - // ignore - } - else if (property_element == xml::qname(xmlns_cp, "revision")) - { - // ignore - } - else - { - unexpected_element(property_element); + properties[property_element.name()] = read_text(); } + skip_remaining_content(property_element); expect_end_element(property_element); } - expect_end_element(xml::qname(xmlns_cp, "coreProperties")); + expect_end_element(root); } -void xlsx_consumer::read_custom_file_properties() +void xlsx_consumer::read_office_document(const std::string &content_type) { -} + static const auto &xmlns = constants::namespace_("workbook"); + static const auto &xmlns_mc = constants::namespace_("mc"); + static const auto &xmlns_r = constants::namespace_("r"); + static const auto &xmlns_s = constants::namespace_("spreadsheetml"); -// Write SpreadsheetML-Specific Package Parts - -void xlsx_consumer::read_workbook() -{ - static const auto &xmlns = constants::get_namespace("workbook"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - static const auto &xmlns_mx = constants::get_namespace("mx"); - static const auto &xmlns_r = constants::get_namespace("r"); - static const auto &xmlns_s = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_x15 = constants::get_namespace("x15"); - static const auto &xmlns_x15ac = constants::get_namespace("x15ac"); - static const auto &xmlns_loext = constants::get_namespace("loext"); - - expect_start_element(xml::qname(xmlns, "workbook"), xml::content::complex); - - if (contains(read_namespaces(), xmlns_x15)) + if (content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" && + content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml") { - target_.enable_x15(); + throw xlnt::invalid_file(content_type); } - skip_attributes({xml::qname(xmlns_mc, "Ignorable")}); + expect_start_element(xml::qname(xmlns, "workbook"), xml::content::complex); + skip_attribute(xml::qname(xmlns_mc, "Ignorable")); + read_namespaces(); while (in_element(xml::qname(xmlns, "workbook"))) { @@ -690,34 +452,35 @@ void xlsx_consumer::read_workbook() if (current_workbook_element == xml::qname(xmlns, "fileVersion")) { - target_.d_->has_file_version_ = true; - target_.d_->file_version_.app_name = parser().attribute("appName"); + detail::workbook_impl::file_version_t file_version; + + if (parser().attribute_present("appName")) + { + file_version.app_name = parser().attribute("appName"); + } if (parser().attribute_present("lastEdited")) { - target_.d_->file_version_.last_edited = parser().attribute("lastEdited"); + file_version.last_edited = parser().attribute("lastEdited"); } if (parser().attribute_present("lowestEdited")) { - target_.d_->file_version_.lowest_edited = parser().attribute("lowestEdited"); + file_version.lowest_edited = parser().attribute("lowestEdited"); } if (parser().attribute_present("lowestEdited")) { - target_.d_->file_version_.rup_build = parser().attribute("rupBuild"); + file_version.rup_build = parser().attribute("rupBuild"); } + + skip_attribute("codeName"); + + target_.d_->file_version_ = file_version; } else if (current_workbook_element == xml::qname(xmlns_mc, "AlternateContent")) { - read_namespaces(); - expect_start_element(xml::qname(xmlns_mc, "Choice"), xml::content::complex); - skip_attributes({"Requires"}); - expect_start_element(xml::qname(xmlns_x15ac, "absPath"), xml::content::simple); - target_.set_absolute_path(path(parser().attribute("url"))); - read_namespaces(); - expect_end_element(xml::qname(xmlns_x15ac, "absPath")); - expect_end_element(xml::qname(xmlns_mc, "Choice")); + skip_remaining_content(xml::qname(xmlns_mc, "AlternateContent")); } else if (current_workbook_element == xml::qname(xmlns, "bookViews")) { @@ -739,18 +502,18 @@ void xlsx_consumer::read_workbook() view.tab_ratio = parser().attribute("tabRatio"); } + skip_attributes(); + expect_end_element(xml::qname(xmlns, "workbookView")); - target_.set_view(view); + target_.view(view); } } else if (current_workbook_element == xml::qname(xmlns, "workbookPr")) { - target_.d_->has_properties_ = true; - if (parser().attribute_present("date1904")) { - target_.set_base_date(is_true(parser().attribute("date1904")) + target_.base_date(is_true(parser().attribute("date1904")) ? calendar::mac_1904 : calendar::windows_1900); } @@ -766,7 +529,7 @@ void xlsx_consumer::read_workbook() expect_start_element(xml::qname(xmlns_s, "sheet"), xml::content::simple); auto title = parser().attribute("name"); - skip_attributes({"state"}); + skip_attribute("state"); sheet_title_index_map_[title] = index++; sheet_title_id_map_[title] = parser().attribute("sheetId"); @@ -777,46 +540,15 @@ void xlsx_consumer::read_workbook() } else if (current_workbook_element == xml::qname(xmlns, "calcPr")) { - target_.d_->has_calculation_properties_ = true; - skip_attributes(); + skip_remaining_content(current_workbook_element); } else if (current_workbook_element == xml::qname(xmlns, "extLst")) { - while (in_element(xml::qname(xmlns, "extLst"))) - { - expect_start_element(xml::qname(xmlns, "ext"), xml::content::complex); - skip_attributes({"uri"}); - read_namespaces(); - - auto ext_element = expect_start_element(xml::content::simple); - - skip_attributes({"stringRefSyntax"}); - - if (ext_element == xml::qname(xmlns_mx, "ArchID")) - { - target_.d_->has_arch_id_ = true; - skip_attributes({"Flags"}); - } - else if (ext_element == xml::qname(xmlns_x15, "workbookPr")) - { - skip_attributes({"chartTrackingRefBase"}); - } - else if (ext_element == xml::qname(xmlns_loext, "extCalcPr")) - { - skip_remaining_content(xml::qname(xmlns_loext, "extCalcPr")); - } - else - { - unexpected_element(ext_element); - } - - expect_end_element(ext_element); - expect_end_element(xml::qname(xmlns, "ext")); - } + skip_remaining_content(current_workbook_element); } else if (current_workbook_element == xml::qname(xmlns, "workbookProtection")) { - skip_remaining_content(xml::qname(xmlns, "workbookProtection")); + skip_remaining_content(current_workbook_element); } else { @@ -827,6 +559,29 @@ void xlsx_consumer::read_workbook() } expect_end_element(xml::qname(xmlns, "workbook")); + + auto workbook_rel = manifest().relationship(path("/"), relationship_type::office_document); + auto workbook_path = workbook_rel.target().path(); + + if (manifest().has_relationship(workbook_path, relationship_type::shared_string_table)) + { + read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::shared_string_table)}); + } + + if (manifest().has_relationship(workbook_path, relationship_type::stylesheet)) + { + read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::stylesheet)}); + } + + if (manifest().has_relationship(workbook_path, relationship_type::theme)) + { + read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::theme)}); + } + + for (auto worksheet_rel : manifest().relationships(workbook_path, relationship_type::worksheet)) + { + read_part({workbook_rel, worksheet_rel}); + } } // Write Workbook Relationship Target Parts @@ -869,30 +624,32 @@ void xlsx_consumer::read_pivot_table() void xlsx_consumer::read_shared_string_table() { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); expect_start_element(xml::qname(xmlns, "sst"), xml::content::complex); skip_attributes({"count"}); + bool has_unique_count = false; std::size_t unique_count = 0; if (parser().attribute_present("uniqueCount")) { + has_unique_count = true; unique_count = parser().attribute("uniqueCount"); } - auto &strings = target_.get_shared_strings(); + auto &strings = target_.shared_strings(); while (in_element(xml::qname(xmlns, "sst"))) { expect_start_element(xml::qname(xmlns, "si"), xml::content::complex); - strings.push_back(read_formatted_text(xmlns)); + strings.push_back(read_formatted_text(xml::qname(xmlns, "si"))); expect_end_element(xml::qname(xmlns, "si")); } expect_end_element(xml::qname(xmlns, "sst")); - if (unique_count != strings.size()) + if (has_unique_count && unique_count != strings.size()) { throw invalid_file("sizes don't match"); } @@ -912,13 +669,12 @@ void xlsx_consumer::read_shared_workbook_user_data() void xlsx_consumer::read_stylesheet() { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - //static const auto &xmlns_x14 = constants::get_namespace("x14"); - static const auto &xmlns_x14ac = constants::get_namespace("x14ac"); - //static const auto &xmlns_x15 = constants::get_namespace("x15"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); + static const auto &xmlns_mc = constants::namespace_("mc"); + static const auto &xmlns_x14ac = constants::namespace_("x14ac"); - auto &stylesheet = target_.impl().stylesheet_; + target_.impl().stylesheet_ = detail::stylesheet(); + auto &stylesheet = target_.impl().stylesheet_.get(); //todo: should this really be defined here? //todo: maybe xlnt::style and xlnt::format can be used here instead now @@ -948,14 +704,8 @@ void xlsx_consumer::read_stylesheet() std::vector format_records; expect_start_element(xml::qname(xmlns, "styleSheet"), xml::content::complex); - - if (contains(read_namespaces(), xmlns_x14ac)) - { - //todo: not enable_x14ac? - target_.enable_x15(); - } - skip_attributes({xml::qname(xmlns_mc, "Ignorable")}); + read_namespaces(); while (in_element(xml::qname(xmlns, "styleSheet"))) { @@ -963,14 +713,13 @@ void xlsx_consumer::read_stylesheet() if (current_style_element == xml::qname(xmlns, "borders")) { - stylesheet.borders.clear(); - + auto &borders = stylesheet.borders; auto count = parser().attribute("count"); while (in_element(xml::qname(xmlns, "borders"))) { - stylesheet.borders.push_back(xlnt::border()); - auto &border = stylesheet.borders.back(); + borders.push_back(xlnt::border()); + auto &border = borders.back(); expect_start_element(xml::qname(xmlns, "border"), xml::content::complex); @@ -1018,21 +767,20 @@ void xlsx_consumer::read_stylesheet() expect_end_element(xml::qname(xmlns, "border")); } - if (count != stylesheet.borders.size()) + if (count != borders.size()) { throw xlnt::exception("border counts don't match"); } } else if (current_style_element == xml::qname(xmlns, "fills")) { - stylesheet.fills.clear(); - + auto &fills = stylesheet.fills; auto count = parser().attribute("count"); while (in_element(xml::qname(xmlns, "fills"))) { - stylesheet.fills.push_back(xlnt::fill()); - auto &new_fill = stylesheet.fills.back(); + fills.push_back(xlnt::fill()); + auto &new_fill = fills.back(); expect_start_element(xml::qname(xmlns, "fill"), xml::content::complex); auto fill_element = expect_start_element(xml::content::complex); @@ -1104,21 +852,20 @@ void xlsx_consumer::read_stylesheet() expect_end_element(xml::qname(xmlns, "fill")); } - if (count != stylesheet.fills.size()) + if (count != fills.size()) { throw xlnt::exception("counts don't match"); } } else if (current_style_element == xml::qname(xmlns, "fonts")) { - stylesheet.fonts.clear(); - + auto &fonts = stylesheet.fonts; auto count = parser().attribute("count"); skip_attributes({xml::qname(xmlns_x14ac, "knownFonts")}); while (in_element(xml::qname(xmlns, "fonts"))) { - stylesheet.fonts.push_back(xlnt::font()); + fonts.push_back(xlnt::font()); auto &new_font = stylesheet.fonts.back(); expect_start_element(xml::qname(xmlns, "font"), xml::content::complex); @@ -1220,8 +967,7 @@ void xlsx_consumer::read_stylesheet() } else if (current_style_element == xml::qname(xmlns, "numFmts")) { - stylesheet.number_formats.clear(); - + auto &number_formats = stylesheet.number_formats; auto count = parser().attribute("count"); while (in_element(xml::qname(xmlns, "numFmts"))) @@ -1237,23 +983,19 @@ void xlsx_consumer::read_stylesheet() xlnt::number_format nf; - nf.set_format_string(format_string); - nf.set_id(parser().attribute("numFmtId")); + nf.format_string(format_string); + nf.id(parser().attribute("numFmtId")); expect_end_element(xml::qname(xmlns, "numFmt")); - stylesheet.number_formats.push_back(nf); + number_formats.push_back(nf); } - if (count != stylesheet.number_formats.size()) + if (count != number_formats.size()) { throw xlnt::exception("counts don't match"); } } - else if (current_style_element == xml::qname(xmlns, "colors")) - { - skip_remaining_content(xml::qname(xmlns, "colors")); - } else if (current_style_element == xml::qname(xmlns, "cellStyles")) { auto count = parser().attribute("count"); @@ -1435,7 +1177,8 @@ void xlsx_consumer::read_stylesheet() } else if (current_style_element == xml::qname(xmlns, "tableStyles")) { - skip_attributes(std::vector{"defaultTableStyle", "defaultPivotStyle"}); + skip_attribute("defaultTableStyle"); + skip_attribute("defaultPivotStyle"); auto count = parser().attribute("count"); std::size_t processed = 0; @@ -1457,9 +1200,32 @@ void xlsx_consumer::read_stylesheet() { skip_remaining_content(current_style_element); } - else if (current_style_element == xml::qname(xmlns, "indexedColors")) + else if (current_style_element == xml::qname(xmlns, "colors")) // CT_Colors 0-1 { - skip_remaining_content(current_style_element); + while (in_element(xml::qname(xmlns, "colors"))) + { + auto colors_child_element = expect_start_element(xml::content::complex); + + if (colors_child_element == xml::qname(xmlns, "indexedColors")) // CT_IndexedColors 0-1 + { + while (in_element(colors_child_element)) + { + expect_start_element(xml::qname(xmlns, "rgbColor"), xml::content::simple); + stylesheet.colors.push_back(read_color()); + expect_end_element(xml::qname(xmlns, "rgbColor")); + } + } + else if (colors_child_element == xml::qname(xmlns, "mruColors")) // CT_MRUColors + { + skip_remaining_content(colors_child_element); + } + else + { + unexpected_element(colors_child_element); + } + + expect_end_element(colors_child_element); + } } else { @@ -1478,7 +1244,7 @@ void xlsx_consumer::read_stylesheet() for (const auto &nf : stylesheet.number_formats) { - if (nf.get_id() == number_format_id) + if (nf.id() == number_format_id) { result = nf; is_custom_number_format = true; @@ -1558,7 +1324,16 @@ void xlsx_consumer::read_stylesheet() void xlsx_consumer::read_theme() { - target_.set_theme(theme()); + auto workbook_rel = manifest().relationship(path("/"), relationship_type::office_document); + auto theme_rel = manifest().relationship(workbook_rel.target().path(), relationship_type::theme); + auto theme_path = manifest().canonicalize({workbook_rel, theme_rel}); + + target_.theme(theme()); + + if (manifest().has_relationship(theme_path, relationship_type::image)) + { + read_part({workbook_rel, theme_rel, manifest().relationship(theme_path, relationship_type::image)}); + } } void xlsx_consumer::read_volatile_dependencies() @@ -1568,10 +1343,10 @@ void xlsx_consumer::read_volatile_dependencies() // CT_Worksheet void xlsx_consumer::read_worksheet(const std::string &rel_id) { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - static const auto &xmlns_x14ac = constants::get_namespace("x14ac"); - static const auto &xmlns_r = constants::get_namespace("r"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); + static const auto &xmlns_mc = constants::namespace_("mc"); + static const auto &xmlns_x14ac = constants::namespace_("x14ac"); + static const auto &xmlns_r = constants::namespace_("r"); auto title = std::find_if(target_.d_->sheet_title_rel_id_map_.begin(), target_.d_->sheet_title_rel_id_map_.end(), @@ -1589,26 +1364,21 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) target_.d_->worksheets_.emplace(insertion_iter, &target_, id, title); - auto ws = target_.get_sheet_by_id(id); + auto ws = target_.sheet_by_id(id); expect_start_element(xml::qname(xmlns, "worksheet"), xml::content::complex); // CT_Worksheet - - if (contains(read_namespaces(), xmlns_x14ac)) - { - ws.enable_x14ac(); - } - skip_attributes({xml::qname(xmlns_mc, "Ignorable")}); + read_namespaces(); xlnt::range_reference full_range; - const auto &shared_strings = target_.get_shared_strings(); - auto &manifest = target_.get_manifest(); + const auto &shared_strings = target_.shared_strings(); + auto &manifest = target_.manifest(); - const auto workbook_rel = manifest.get_relationship(path("/"), relationship::type::office_document); - const auto sheet_rel = manifest.get_relationship(workbook_rel.get_target().get_path(), rel_id); - path sheet_path(sheet_rel.get_source().get_path().parent().append(sheet_rel.get_target().get_path())); - auto hyperlinks = manifest.get_relationships(sheet_path, xlnt::relationship::type::hyperlink); + const auto workbook_rel = manifest.relationship(path("/"), relationship_type::office_document); + const auto sheet_rel = manifest.relationship(workbook_rel.target().path(), rel_id); + path sheet_path(sheet_rel.source().path().parent().append(sheet_rel.target().path())); + auto hyperlinks = manifest.relationships(sheet_path, xlnt::relationship_type::hyperlink); while (in_element(xml::qname(xmlns, "worksheet"))) { @@ -1625,8 +1395,87 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) } else if (current_worksheet_element == xml::qname(xmlns, "sheetViews")) // CT_SheetViews 0-1 { - ws.d_->has_view_ = true; - skip_remaining_content(current_worksheet_element); + while (in_element(current_worksheet_element)) + { + expect_start_element(xml::qname(xmlns, "sheetView"), xml::content::complex); // CT_SheetView 1+ + + sheet_view new_view; + new_view.id(parser().attribute("workbookViewId")); + + if (parser().attribute_present("showGridLines")) // default="true" + { + new_view.show_grid_lines(is_true(parser().attribute("showGridLines"))); + } + + if (parser().attribute_present("defaultGridColor")) // default="true" + { + new_view.default_grid_color(is_true(parser().attribute("defaultGridColor"))); + } + + skip_attributes({"windowProtection", "showFormulas", "showRowColHeaders", "showZeros", + "rightToLeft", "tabSelected", "showRuler", "showOutlineSymbols", "showWhiteSpace", "view", + "topLeftCell", "colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView", + "zoomScalePageLayoutView"}); + + while (in_element(xml::qname(xmlns, "sheetView"))) + { + auto sheet_view_child_element = expect_start_element(xml::content::simple); + + if (sheet_view_child_element == xml::qname(xmlns, "pane")) // CT_Pane 0-1 + { + pane new_pane; + + if (parser().attribute_present("topLeftCell")) + { + new_pane.top_left_cell = cell_reference(parser().attribute("topLeftCell")); + } + + if (parser().attribute_present("xSplit")) + { + new_pane.x_split = parser().attribute("xSplit"); + } + + if (parser().attribute_present("ySplit")) + { + new_pane.y_split = parser().attribute("ySplit"); + } + + if (parser().attribute_present("activePane")) + { + new_pane.active_pane = parser().attribute("activePane"); + } + + if (parser().attribute_present("state")) + { + new_pane.state = parser().attribute("state"); + } + + new_view.pane(new_pane); + } + else if (sheet_view_child_element == xml::qname(xmlns, "selection")) // CT_Selection 0-4 + { + skip_remaining_content(sheet_view_child_element); + } + else if (sheet_view_child_element == xml::qname(xmlns, "pivotSelection")) // CT_PivotSelection 0-4 + { + skip_remaining_content(sheet_view_child_element); + } + else if (sheet_view_child_element == xml::qname(xmlns, "extLst")) // CT_ExtensionList 0-1 + { + skip_remaining_content(sheet_view_child_element); + } + else + { + unexpected_element(sheet_view_child_element); + } + + expect_end_element(sheet_view_child_element); + } + + expect_end_element(xml::qname(xmlns, "sheetView")); + + ws.d_->views_.push_back(new_view); + } } else if (current_worksheet_element == xml::qname(xmlns, "sheetFormatPr")) // CT_SheetFormatPr 0-1 { @@ -1669,25 +1518,17 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) while (in_element(xml::qname(xmlns, "sheetData"))) { expect_start_element(xml::qname(xmlns, "row"), xml::content::complex); // CT_Row - auto row_index = static_cast(std::stoull(parser().attribute("r"))); + auto row_index = parser().attribute("r"); if (parser().attribute_present("ht")) { - ws.get_row_properties(row_index).height = std::stold(parser().attribute("ht")); + ws.row_properties(row_index).height = parser().attribute("ht"); } - if (parser().attribute_present("customHeight")) - { - auto custom_height = parser().attribute("customHeight"); + skip_attribute("customHeight"); - if (custom_height != "false") - { - ws.get_row_properties(row_index).height = std::stold(custom_height); - } - } - - auto min_column = full_range.get_top_left().get_column_index(); - auto max_column = full_range.get_bottom_right().get_column_index(); + auto min_column = full_range.top_left().column_index(); + auto max_column = full_range.bottom_right().column_index(); if (parser().attribute_present("spans")) { @@ -1708,7 +1549,7 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) while (in_element(xml::qname(xmlns, "row"))) { expect_start_element(xml::qname(xmlns, "c"), xml::content::complex); - auto cell = ws.get_cell(cell_reference(parser().attribute("r"))); + auto cell = ws.cell(cell_reference(parser().attribute("r"))); auto has_type = parser().attribute_present("t"); auto type = has_type ? parser().attribute("t") : ""; @@ -1761,40 +1602,40 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) expect_end_element(xml::qname(xmlns, "c")); - if (has_formula && !has_shared_formula && !ws.get_workbook().get_data_only()) + if (has_formula && !has_shared_formula) { - cell.set_formula(formula_value_string); + cell.formula(formula_value_string); } if (has_type && (type == "inlineStr" || type == "str")) { - cell.set_value(value_string); + cell.value(value_string); } else if (has_type && type == "s" && !has_formula) { auto shared_string_index = static_cast(std::stoull(value_string)); auto shared_string = shared_strings.at(shared_string_index); - cell.set_value(shared_string); + cell.value(shared_string); } else if (has_type && type == "b") // boolean { - cell.set_value(value_string != "0"); + cell.value(value_string != "0"); } else if (has_value && !value_string.empty()) { if (!value_string.empty() && value_string[0] == '#') { - cell.set_error(value_string); + cell.error(value_string); } else { - cell.set_value(std::stold(value_string)); + cell.value(std::stold(value_string)); } } if (has_format) { - cell.format(target_.get_format(format_id)); + cell.format(target_.format(format_id)); } } @@ -1869,14 +1710,14 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) { expect_start_element(xml::qname(xmlns, "hyperlink"), xml::content::simple); - auto cell = ws.get_cell(parser().attribute("ref")); + auto cell = ws.cell(parser().attribute("ref")); auto hyperlink_rel_id = parser().attribute(xml::qname(xmlns_r, "id")); auto hyperlink_rel = std::find_if(hyperlinks.begin(), hyperlinks.end(), - [&](const relationship &r) { return r.get_id() == hyperlink_rel_id; }); + [&](const relationship &r) { return r.id() == hyperlink_rel_id; }); if (hyperlink_rel != hyperlinks.end()) { - cell.set_hyperlink(hyperlink_rel->get_target().get_path().string()); + cell.hyperlink(hyperlink_rel->target().path().string()); } expect_end_element(xml::qname(xmlns, "hyperlink")); @@ -1890,14 +1731,14 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) { page_margins margins; - margins.set_top(parser().attribute("top")); - margins.set_bottom(parser().attribute("bottom")); - margins.set_left(parser().attribute("left")); - margins.set_right(parser().attribute("right")); - margins.set_header(parser().attribute("header")); - margins.set_footer(parser().attribute("footer")); + margins.top(parser().attribute("top")); + margins.bottom(parser().attribute("bottom")); + margins.left(parser().attribute("left")); + margins.right(parser().attribute("right")); + margins.header(parser().attribute("header")); + margins.footer(parser().attribute("footer")); - ws.set_page_margins(margins); + ws.page_margins(margins); } else if (current_worksheet_element == xml::qname(xmlns, "pageSetup")) // CT_PageSetup 0-1 { @@ -1949,10 +1790,10 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) expect_end_element(xml::qname(xmlns, "worksheet")); - if (manifest.has_relationship(sheet_path, xlnt::relationship::type::comments)) + if (manifest.has_relationship(sheet_path, xlnt::relationship_type::comments)) { auto comments_part = manifest.canonicalize( - {workbook_rel, sheet_rel, manifest.get_relationship(sheet_path, xlnt::relationship::type::comments)}); + {workbook_rel, sheet_rel, manifest.relationship(sheet_path, xlnt::relationship_type::comments)}); auto receive = xml::parser::receive_default; xml::parser parser(archive_->open(comments_part.string()), comments_part.string(), receive); @@ -1960,10 +1801,10 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id) read_comments(ws); - if (manifest.has_relationship(sheet_path, xlnt::relationship::type::vml_drawing)) + if (manifest.has_relationship(sheet_path, xlnt::relationship_type::vml_drawing)) { auto vml_drawings_part = manifest.canonicalize({workbook_rel, sheet_rel, - manifest.get_relationship(sheet_path, xlnt::relationship::type::vml_drawing)}); + manifest.relationship(sheet_path, xlnt::relationship_type::vml_drawing)}); xml::parser vml_parser(archive_->open(vml_drawings_part.string()), vml_drawings_part.string(), receive); parser_ = &vml_parser; @@ -1981,7 +1822,7 @@ void xlsx_consumer::read_vml_drawings(worksheet/*ws*/) void xlsx_consumer::read_comments(worksheet ws) { - static const auto &xmlns = xlnt::constants::get_namespace("spreadsheetml"); + static const auto &xmlns = xlnt::constants::namespace_("spreadsheetml"); std::vector authors; @@ -2007,7 +1848,7 @@ void xlsx_consumer::read_comments(worksheet ws) expect_start_element(xml::qname(xmlns, "text"), xml::content::complex); - ws.get_cell(cell_ref).comment(comment(read_formatted_text(xmlns), authors.at(author_id))); + ws.cell(cell_ref).comment(comment(read_formatted_text(xml::qname(xmlns, "text")), authors.at(author_id))); expect_end_element(xml::qname(xmlns, "text")); expect_end_element(xml::qname(xmlns, "comment")); @@ -2031,6 +1872,14 @@ void xlsx_consumer::read_unknown_relationships() { } +void xlsx_consumer::read_image(const xlnt::path &image_path) +{ + auto &in_stream = archive_->open(image_path.string()); + vector_ostreambuf buffer(target_.d_->images_[image_path.string()]); + std::ostream out_stream(&buffer); + out_stream << in_stream.rdbuf(); +} + std::string xlsx_consumer::read_text() { auto text = std::string(); @@ -2071,6 +1920,22 @@ void xlsx_consumer::skip_attributes() parser().attribute_map(); } +void xlsx_consumer::skip_attribute(const xml::qname &name) +{ + if (parser().attribute_present(name)) + { + parser().attribute(name); + } +} + +void xlsx_consumer::skip_attribute(const std::string &name) +{ + if (parser().attribute_present(name)) + { + parser().attribute(name); + } +} + void xlsx_consumer::skip_remaining_content(const xml::qname &name) { // start by assuming we've already parsed the opening tag @@ -2145,87 +2010,112 @@ void xlsx_consumer::expect_end_element(const xml::qname &name) stack_.pop_back(); } -formatted_text xlsx_consumer::read_formatted_text(const std::string &xmlns) +formatted_text xlsx_consumer::read_formatted_text(const xml::qname &parent) { + const auto &xmlns = parent.namespace_(); formatted_text t; - auto text_element = expect_start_element(xml::content::mixed); - skip_attributes(); - - if (text_element == xml::qname(xmlns, "t")) + while (in_element(parent)) { - t.plain_text(read_text()); - } - else if (text_element == xml::qname(xmlns, "r")) - { - parser().content(xml::content::complex); + auto text_element = expect_start_element(xml::content::mixed); + skip_attributes(); + auto text = read_text(); - text_run run; - - while (in_element(xml::qname(xmlns, "r"))) + if (text_element == xml::qname(xmlns, "t")) { - auto run_element = expect_start_element(xml::content::mixed); - - if (run_element == xml::qname(xmlns, "rPr")) - { - parser().content(xml::content::complex); - - while (in_element(xml::qname(xmlns, "rPr"))) - { - auto current_run_property_element = expect_start_element(xml::content::simple); - - if (current_run_property_element == xml::qname(xmlns, "sz")) - { - run.set_size(parser().attribute("val")); - } - else if (current_run_property_element == xml::qname(xmlns, "rFont")) - { - run.set_font(parser().attribute("val")); - } - else if (current_run_property_element == xml::qname(xmlns, "color")) - { - run.set_color(read_color()); - } - else if (current_run_property_element == xml::qname(xmlns, "family")) - { - run.set_family(parser().attribute("val")); - } - else if (current_run_property_element == xml::qname(xmlns, "scheme")) - { - run.set_scheme(parser().attribute("val")); - } - else if (current_run_property_element == xml::qname(xmlns, "b")) - { - run.set_bold(parser().attribute_present("val") ? is_true(parser().attribute("val")) : true); - } - else - { - unexpected_element(current_run_property_element); - } - - expect_end_element(current_run_property_element); - } - } - else if (run_element == xml::qname(xmlns, "t")) - { - run.set_string(read_text()); - } - else - { - unexpected_element(run_element); - } - - expect_end_element(run_element); + t.plain_text(text); } - - t.add_run(run); - } - else - { - unexpected_element(text_element); - } + else if (text_element == xml::qname(xmlns, "r")) + { + text_run run; - expect_end_element(text_element); + while (in_element(xml::qname(xmlns, "r"))) + { + auto run_element = expect_start_element(xml::content::mixed); + auto run_text = read_text(); + + if (run_element == xml::qname(xmlns, "rPr")) + { + while (in_element(xml::qname(xmlns, "rPr"))) + { + auto current_run_property_element = expect_start_element(xml::content::simple); + + if (current_run_property_element == xml::qname(xmlns, "sz")) + { + run.size(parser().attribute("val")); + } + else if (current_run_property_element == xml::qname(xmlns, "rFont")) + { + run.font(parser().attribute("val")); + } + else if (current_run_property_element == xml::qname(xmlns, "color")) + { + run.color(read_color()); + } + else if (current_run_property_element == xml::qname(xmlns, "family")) + { + run.family(parser().attribute("val")); + } + else if (current_run_property_element == xml::qname(xmlns, "scheme")) + { + run.scheme(parser().attribute("val")); + } + else if (current_run_property_element == xml::qname(xmlns, "b")) + { + run.bold(parser().attribute_present("val") ? is_true(parser().attribute("val")) : true); + } + else if (current_run_property_element == xml::qname(xmlns, "u")) + { + if (parser().attribute_present("val")) + { + run.underline(parser().attribute("val")); + } + else + { + run.underline(font::underline_style::single); + } + } + else + { + unexpected_element(current_run_property_element); + } + + expect_end_element(current_run_property_element); + read_text(); + } + } + else if (run_element == xml::qname(xmlns, "t")) + { + run.string(run_text); + } + else + { + unexpected_element(run_element); + } + + read_text(); + expect_end_element(run_element); + read_text(); + } + + t.add_run(run); + } + else if (text_element == xml::qname(xmlns, "rPh")) + { + skip_remaining_content(text_element); + } + else if (text_element == xml::qname(xmlns, "phoneticPr")) + { + skip_remaining_content(text_element); + } + else + { + unexpected_element(text_element); + } + + read_text(); + expect_end_element(text_element); + } return t; } @@ -2235,8 +2125,9 @@ xlnt::color xlsx_consumer::read_color() { xlnt::color result; - if (parser().attribute_present("auto")) + if (parser().attribute_present("auto") && is_true(parser().attribute("auto"))) { + result.auto_(true); return result; } @@ -2255,19 +2146,15 @@ xlnt::color xlsx_consumer::read_color() if (parser().attribute_present("tint")) { - result.set_tint(parser().attribute("tint", 0.0)); + result.tint(parser().attribute("tint", 0.0)); } return result; } -void xlsx_consumer::check_document_type(const std::string &document_content_type) +manifest &xlsx_consumer::manifest() { - if (document_content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" && - document_content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml ") - { - throw xlnt::invalid_file(document_content_type); - } + return target_.manifest(); } } // namespace detail diff --git a/source/detail/xlsx_consumer.hpp b/source/detail/xlsx_consumer.hpp index f64d899f..7f3d5559 100644 --- a/source/detail/xlsx_consumer.hpp +++ b/source/detail/xlsx_consumer.hpp @@ -37,6 +37,7 @@ namespace xlnt { class color; class formatted_text; +class manifest; class path; class relationship; class workbook; @@ -59,52 +60,36 @@ public: void read(std::istream &source, const std::string &password); private: - /// - /// Ignore all remaining elements at the same depth in the current XML parser. - /// - void skip_remaining_elements(); - - /// - /// Convenience method to dereference the pointer to the current parser to avoid - /// having to use "parser_->" constantly. - /// - xml::parser &parser(); - /// /// Read all the files needed from the XLSX archive and initialize all of /// the data in the workbook to match. /// void populate_workbook(); - // Package Parts + /// + /// + /// + void read_content_types(); + + // Metadata Readers + + /// + /// Read core, extended, and custom properties. + /// + void read_metadata_properties(); /// - /// Parse content types ([Content_Types].xml) and package relationships (_rels/.rels). + /// Parse the core properties about the current package. /// - void read_manifest(); + void read_properties(const path &part, const xml::qname &root); - /// - /// Parse the core properties about the current package (usually docProps/core.xml). - /// - void read_core_properties(); - - /// - /// Parse extra application-speicific package properties (usually docProps/app.xml). - void read_extended_properties(); - - /// - /// Parse custom file properties. These aren't associated with a particular application - /// but extensions to OOXML can use this part to hold extra data about the package. - /// - void read_custom_file_properties(); - - // SpreadsheetML-Specific Package Parts + // SpreadsheetML-Specific Package Part Readers /// /// Parse the main XML document about the workbook and then all child relationships /// of the workbook (e.g. worksheets). /// - void read_workbook(); + void read_office_document(const std::string &content_type); // Workbook Relationship Target Parts @@ -221,37 +206,135 @@ private: /// /// void read_unknown_relationships(); - + + /// + /// + /// + void read_image(const path &part); + + // Common Section Readers + + /// + /// Read part from the archive and return a vector of relationships + /// based on the content of that part. + /// std::vector read_relationships(const path &part); - - std::string read_text(); - - formatted_text read_formatted_text(const std::string &xmlns); - - void read_part(const std::vector &rel_chain); - - void skip_attributes(); - - void skip_attributes(const std::vector &names); - - void skip_attributes(const std::vector &names); - - void skip_remaining_content(const xml::qname &name); - - xml::qname expect_start_element(xml::content content); - - void expect_start_element(const xml::qname &name, xml::content content); - - void expect_end_element(const xml::qname &name); - - bool in_element(const xml::qname &name); + /// + /// Read a CT_Color from the document currently being parsed. + /// color read_color(); - void check_document_type(const std::string &document_content_type); + /// + /// Read a rich text CT_RElt from the document currently being parsed. + /// + formatted_text read_formatted_text(const xml::qname &parent); + /// + /// Returns true if the givent document type represents an XLSX file. + /// + bool document_type_is_xlsx(const std::string &document_content_type); + + // SAX Parsing Helpers + + /// + /// In mixed content XML elements, whitespace before and after is not ignored. + /// Additionally, if PCDATA spans the boundary of the XML read buffer, it will + /// be parsed as two separate strings instead of on longer string. This method + /// will read character data until non-character data is peek()ed from the parser + /// and returns the combined strings. This should be used when parsing mixed + /// content to ignore whitespace and whenever character data is expected between + /// tags. + /// + std::string read_text(); + + /// + /// Read the part from the archive and parse it as XML. After this is called, + /// xlsx_consumer::parser() will return a reference to the parser that reads + /// this part. + /// + void read_part(const std::vector &rel_chain); + + /// + /// libstudxml will throw an exception if all attributes on an element are not + /// read with xml::parser::attribute(const std::string &). This should therefore + /// be called if every remaining attribute should be ignored on an element. + /// + void skip_attributes(); + + /// + /// Skip attribute name if it exists on the currently parsed element in the XML + /// parser. + /// + void skip_attribute(const std::string &name); + + /// + /// Skip attribute name if it exists on the currently parsed element in the XML + /// parser. + /// + void skip_attribute(const xml::qname &name); + + /// + /// Call skip_attribute on every name in names. + /// + void skip_attributes(const std::vector &names); + + /// + /// Call skip_attribute on every name in names. + /// + void skip_attributes(const std::vector &names); + + /// + /// Read all content in name until the closing tag is reached. + /// The closing tag will not be handled after this is called. + /// + void skip_remaining_content(const xml::qname &name); + + /// + /// Handles the next event in the XML parser and throws an exception + /// if it is not the start of an element. Additionally sets the content + /// type of the element to content. + /// + xml::qname expect_start_element(xml::content content); + + /// + /// Handles the next event in the XML parser and throws an exception + /// if the next element is not named name. Sets the content type of + /// the element to content. + /// + void expect_start_element(const xml::qname &name, xml::content content); + + /// + /// Throws an exception if the next event in the XML parser is not + /// the end of element called name. + /// + void expect_end_element(const xml::qname &name); + + /// + /// Returns true if the top of the parsing stack is called name and + /// the end of that element hasn't been reached in the XML document. + /// + bool in_element(const xml::qname &name); + + /// + /// Handles all start and end namespace events from the current parser + /// and returns a vector of strings containing the URL for each namespace. + /// std::vector read_namespaces(); + // Properties + + /// + /// Convenience method to dereference the pointer to the current parser to avoid + /// having to use "parser_->" constantly. + /// + xml::parser &parser(); + + /// + /// Convenience method to access the target workbook's manifest. + /// + manifest &manifest(); + /// /// The ZIP file containing the files that make up the OOXML package. /// diff --git a/source/detail/xlsx_crypto.cpp b/source/detail/xlsx_crypto.cpp index b39a3289..7067b1bf 100644 --- a/source/detail/xlsx_crypto.cpp +++ b/source/detail/xlsx_crypto.cpp @@ -172,7 +172,7 @@ struct crypto_helper return std::vector(hash.begin(), hash.end()); } - static std::vector get_file(POLE::Storage &storage, const std::string &name) + static std::vector file(POLE::Storage &storage, const std::string &name) { POLE::Stream stream(&storage, name.c_str()); if (stream.fail()) return {}; @@ -389,8 +389,8 @@ struct crypto_helper static std::vector write_agile_encryption_info(const std::string &password) { - static const auto &xmlns = xlnt::constants::get_namespace("encryption"); - static const auto &xmlns_p = xlnt::constants::get_namespace("encryption-password"); + static const auto &xmlns = xlnt::constants::namespace_("encryption"); + static const auto &xmlns_p = xlnt::constants::namespace_("encryption-password"); std::vector encryption_info; xlnt::detail::vector_ostreambuf encryption_info_buffer(encryption_info); @@ -445,9 +445,9 @@ struct crypto_helper static std::vector decrypt_xlsx_agile(const std::vector &encryption_info, const std::string &password, const std::vector &encrypted_package) { - static const auto &xmlns = xlnt::constants::get_namespace("encryption"); - static const auto &xmlns_p = xlnt::constants::get_namespace("encryption-password"); - //static const auto &xmlns_c = xlnt::constants::get_namespace("encryption-certificate"); + static const auto &xmlns = xlnt::constants::namespace_("encryption"); + static const auto &xmlns_p = xlnt::constants::namespace_("encryption-password"); + //static const auto &xmlns_c = xlnt::constants::namespace_("encryption-certificate"); agile_encryption_info result; @@ -652,8 +652,8 @@ struct crypto_helper throw xlnt::exception("not an ole compound file"); } - auto encrypted_package = get_file(storage, "EncryptedPackage"); - auto encryption_info = get_file(storage, "EncryptionInfo"); + auto encrypted_package = file(storage, "EncryptedPackage"); + auto encryption_info = file(storage, "EncryptionInfo"); std::size_t index = 0; diff --git a/source/detail/xlsx_producer.cpp b/source/detail/xlsx_producer.cpp index 1a270ef5..721c41ce 100644 --- a/source/detail/xlsx_producer.cpp +++ b/source/detail/xlsx_producer.cpp @@ -42,11 +42,6 @@ using namespace std::string_literals; namespace { -/// -/// Some XML elements do unknown things and will be skipped during writing if this is true. -/// -const bool skip_unknown_elements = true; - /// /// Returns true if d is exactly equal to an integer. /// @@ -55,26 +50,6 @@ bool is_integral(long double d) return std::fabs(d - static_cast(static_cast(d))) == 0.L; } -std::string fill(const std::string &string, std::size_t length = 2) -{ - if (string.size() >= length) - { - return string; - } - - return std::string(length - string.size(), '0') + string; -} - -std::string datetime_to_w3cdtf(const xlnt::datetime &dt) -{ - return std::to_string(dt.year) + "-" - + fill(std::to_string(dt.month)) + "-" - + fill(std::to_string(dt.day)) + "T" - + fill(std::to_string(dt.hour)) + ":" - + fill(std::to_string(dt.minute)) + ":" - + fill(std::to_string(dt.second)) + "Z"; -} - } // namespace namespace xlnt { @@ -97,69 +72,69 @@ void xlsx_producer::populate_archive() { write_content_types(); - const auto root_rels = source_.get_manifest().get_relationships(path("/")); + const auto root_rels = source_.manifest().relationships(path("/")); write_relationships(root_rels, path("/")); for (auto &rel : root_rels) { // thumbnail is binary content so we don't want to open an xml serializer stream - if (rel.get_type() == relationship::type::thumbnail) + if (rel.type() == relationship_type::thumbnail) { - write_thumbnail(rel); + write_image(rel.target().path()); continue; } - begin_part(rel.get_target().get_path()); + begin_part(rel.target().path()); - switch (rel.get_type()) + switch (rel.type()) { - case relationship::type::core_properties: + case relationship_type::core_properties: write_core_properties(rel); break; - case relationship::type::extended_properties: + case relationship_type::extended_properties: write_extended_properties(rel); break; - case relationship::type::custom_properties: + case relationship_type::custom_properties: write_custom_properties(rel); break; - case relationship::type::office_document: + case relationship_type::office_document: write_workbook(rel); break; - case relationship::type::thumbnail: break; - case relationship::type::calculation_chain: break; - case relationship::type::worksheet: break; - case relationship::type::shared_string_table: break; - case relationship::type::stylesheet: break; - case relationship::type::theme: break; - case relationship::type::hyperlink: break; - case relationship::type::chartsheet: break; - case relationship::type::comments: break; - case relationship::type::vml_drawing: break; - case relationship::type::unknown: break; - case relationship::type::printer_settings: break; - case relationship::type::connections: break; - case relationship::type::custom_property: break; - case relationship::type::custom_xml_mappings: break; - case relationship::type::dialogsheet: break; - case relationship::type::drawings: break; - case relationship::type::external_workbook_references: break; - case relationship::type::metadata: break; - case relationship::type::pivot_table: break; - case relationship::type::pivot_table_cache_definition: break; - case relationship::type::pivot_table_cache_records: break; - case relationship::type::query_table: break; - case relationship::type::shared_workbook_revision_headers: break; - case relationship::type::shared_workbook: break; - case relationship::type::revision_log: break; - case relationship::type::shared_workbook_user_data: break; - case relationship::type::single_cell_table_definitions: break; - case relationship::type::table_definition: break; - case relationship::type::volatile_dependencies: break; - case relationship::type::image: break; + case relationship_type::thumbnail: break; + case relationship_type::calculation_chain: break; + case relationship_type::worksheet: break; + case relationship_type::shared_string_table: break; + case relationship_type::stylesheet: break; + case relationship_type::theme: break; + case relationship_type::hyperlink: break; + case relationship_type::chartsheet: break; + case relationship_type::comments: break; + case relationship_type::vml_drawing: break; + case relationship_type::unknown: break; + case relationship_type::printer_settings: break; + case relationship_type::connections: break; + case relationship_type::custom_property: break; + case relationship_type::custom_xml_mappings: break; + case relationship_type::dialogsheet: break; + case relationship_type::drawings: break; + case relationship_type::external_workbook_references: break; + case relationship_type::metadata: break; + case relationship_type::pivot_table: break; + case relationship_type::pivot_table_cache_definition: break; + case relationship_type::pivot_table_cache_records: break; + case relationship_type::query_table: break; + case relationship_type::shared_workbook_revision_headers: break; + case relationship_type::shared_workbook: break; + case relationship_type::revision_log: break; + case relationship_type::shared_workbook_user_data: break; + case relationship_type::single_cell_table_definitions: break; + case relationship_type::table_definition: break; + case relationship_type::volatile_dependencies: break; + case relationship_type::image: break; } } @@ -199,21 +174,21 @@ void xlsx_producer::write_content_types() serializer().start_element(xmlns, "Types"); serializer().namespace_decl(xmlns, ""); - for (const auto &extension : source_.get_manifest().get_extensions_with_default_types()) + for (const auto &extension : source_.manifest().extensions_with_default_types()) { serializer().start_element(xmlns, "Default"); serializer().attribute("Extension", extension); serializer().attribute("ContentType", - source_.get_manifest().get_default_type(extension)); + source_.manifest().default_type(extension)); serializer().end_element(xmlns, "Default"); } - for (const auto &part : source_.get_manifest().get_parts_with_overriden_types()) + for (const auto &part : source_.manifest().parts_with_overriden_types()) { serializer().start_element(xmlns, "Override"); serializer().attribute("PartName", part.resolve(path("/")).string()); serializer().attribute("ContentType", - source_.get_manifest().get_override_type(part)); + source_.manifest().override_type(part)); serializer().end_element(xmlns, "Override"); } @@ -229,9 +204,20 @@ void xlsx_producer::write_extended_properties(const relationship &/*rel*/) serializer().namespace_decl(xmlns, ""); serializer().namespace_decl(xmlns_vt, "vt"); - serializer().element(xmlns, "Application", source_.get_application()); - serializer().element(xmlns, "DocSecurity", source_.get_doc_security()); - serializer().element(xmlns, "ScaleCrop", source_.get_scale_crop() ? "true" : "false"); + if (source_.has_core_property("Application")) + { + serializer().element(xmlns, "Application", source_.core_property("Application")); + } + + if (source_.has_core_property("DocSecurity")) + { + serializer().element(xmlns, "DocSecurity", source_.core_property("DocSecurity")); + } + + if (source_.has_core_property("ScaleCrop")) + { + serializer().element(xmlns, "ScaleCrop", source_.core_property("ScaleCrop")); + } serializer().start_element(xmlns, "HeadingPairs"); serializer().start_element(xmlns_vt, "vector"); @@ -241,48 +227,59 @@ void xlsx_producer::write_extended_properties(const relationship &/*rel*/) serializer().element(xmlns_vt, "lpstr", "Worksheets"); serializer().end_element(xmlns_vt, "variant"); serializer().start_element(xmlns_vt, "variant"); - serializer().element(xmlns_vt, "i4", source_.get_sheet_titles().size()); + serializer().element(xmlns_vt, "i4", source_.sheet_titles().size()); serializer().end_element(xmlns_vt, "variant"); serializer().end_element(xmlns_vt, "vector"); serializer().end_element(xmlns, "HeadingPairs"); serializer().start_element(xmlns, "TitlesOfParts"); serializer().start_element(xmlns_vt, "vector"); - serializer().attribute("size", source_.get_sheet_titles().size()); + serializer().attribute("size", source_.sheet_titles().size()); serializer().attribute("baseType", "lpstr"); for (auto ws : source_) { - serializer().element(xmlns_vt, "lpstr", ws.get_title()); + serializer().element(xmlns_vt, "lpstr", ws.title()); } serializer().end_element(xmlns_vt, "vector"); serializer().end_element(xmlns, "TitlesOfParts"); - serializer().start_element(xmlns, "Company"); - - if (!source_.get_company().empty()) + if (source_.has_core_property("Company")) { - serializer().characters(source_.get_company()); + serializer().element(xmlns, "Company", source_.core_property("Company")); } - - serializer().end_element(xmlns, "Company"); - serializer().element(xmlns, "LinksUpToDate", source_.links_up_to_date() ? "true" : "false"); - serializer().element(xmlns, "SharedDoc", source_.is_shared_doc() ? "true" : "false"); - serializer().element(xmlns, "HyperlinksChanged", source_.hyperlinks_changed() ? "true" : "false"); - serializer().element(xmlns, "AppVersion", source_.get_app_version()); + if (source_.has_core_property("LinksUpToDate")) + { + serializer().element(xmlns, "LinksUpToDate", source_.core_property("LinksUpToDate")); + } + + if (source_.has_core_property("LinksUpToDate")) + { + serializer().element(xmlns, "SharedDoc", source_.core_property("SharedDoc")); + } + + if (source_.has_core_property("LinksUpToDate")) + { + serializer().element(xmlns, "HyperlinksChanged", source_.core_property("HyperlinksChanged")); + } + + if (source_.has_core_property("LinksUpToDate")) + { + serializer().element(xmlns, "AppVersion", source_.core_property("AppVersion")); + } serializer().end_element(xmlns, "Properties"); } void xlsx_producer::write_core_properties(const relationship &/*rel*/) { - static const auto &xmlns_cp = constants::get_namespace("core-properties"); - static const auto &xmlns_dc = constants::get_namespace("dc"); - static const auto &xmlns_dcterms = constants::get_namespace("dcterms"); - static const auto &xmlns_dcmitype = constants::get_namespace("dcmitype"); - static const auto &xmlns_xsi = constants::get_namespace("xsi"); + static const auto &xmlns_cp = constants::namespace_("core-properties"); + static const auto &xmlns_dc = constants::namespace_("dc"); + static const auto &xmlns_dcterms = constants::namespace_("dcterms"); + static const auto &xmlns_dcmitype = constants::namespace_("dcmitype"); + static const auto &xmlns_xsi = constants::namespace_("xsi"); serializer().start_element(xmlns_cp, "coreProperties"); serializer().namespace_decl(xmlns_cp, "cp"); @@ -291,28 +288,55 @@ void xlsx_producer::write_core_properties(const relationship &/*rel*/) serializer().namespace_decl(xmlns_dcmitype, "dcmitype"); serializer().namespace_decl(xmlns_xsi, "xsi"); - serializer().element(xmlns_dc, "creator", source_.get_creator()); - serializer().element(xmlns_cp, "lastModifiedBy", source_.get_last_modified_by()); - serializer().start_element(xmlns_dcterms, "created"); - serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF"); - serializer().characters(datetime_to_w3cdtf(source_.get_created())); - serializer().end_element(xmlns_dcterms, "created"); - serializer().start_element(xmlns_dcterms, "modified"); - serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF"); - serializer().characters(datetime_to_w3cdtf(source_.get_modified())); - serializer().end_element(xmlns_dcterms, "modified"); + if (source_.has_core_property("creator")) + { + serializer().element(xmlns_dc, "creator", source_.core_property("creator")); + } - if (!source_.get_title().empty()) + if (source_.has_core_property("lastModifiedBy")) + { + serializer().element(xmlns_cp, "lastModifiedBy", source_.core_property("lastModifiedBy")); + } + + if (source_.has_core_property("created")) + { + serializer().start_element(xmlns_dcterms, "created"); + serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF"); + serializer().characters(source_.core_property("created")); + serializer().end_element(xmlns_dcterms, "created"); + } + + if (source_.has_core_property("modified")) + { + serializer().start_element(xmlns_dcterms, "modified"); + serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF"); + serializer().characters(source_.core_property("modified")); + serializer().end_element(xmlns_dcterms, "modified"); + } + + if (source_.has_title()) { - serializer().element(xmlns_dc, "title", source_.get_title()); + serializer().element(xmlns_dc, "title", source_.title()); } - if (!skip_unknown_elements) + if (source_.has_core_property("description")) { - serializer().element(xmlns_dc, "description", ""); - serializer().element(xmlns_dc, "subject", ""); - serializer().element(xmlns_cp, "keywords", ""); - serializer().element(xmlns_cp, "category", ""); + serializer().element(xmlns_dc, "description", source_.core_property("description")); + } + + if (source_.has_core_property("subject")) + { + serializer().element(xmlns_dc, "subject", source_.core_property("subject")); + } + + if (source_.has_core_property("keywords")) + { + serializer().element(xmlns_cp, "keywords", source_.core_property("keywords")); + } + + if (source_.has_core_property("category")) + { + serializer().element(xmlns_cp, "category", source_.core_property("category")); } serializer().end_element(xmlns_cp, "coreProperties"); @@ -332,7 +356,7 @@ void xlsx_producer::write_workbook(const relationship &rel) for (auto ws : source_) { - if (!ws.has_page_setup() || ws.get_page_setup().get_sheet_state() == sheet_state::visible) + if (!ws.has_page_setup() || ws.page_setup().sheet_state() == sheet_state::visible) { num_visible++; } @@ -348,91 +372,58 @@ void xlsx_producer::write_workbook(const relationship &rel) throw no_visible_worksheets(); } - static const auto &xmlns = constants::get_namespace("workbook"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - static const auto &xmlns_mx = constants::get_namespace("mx"); - static const auto &xmlns_r = constants::get_namespace("r"); - static const auto &xmlns_s = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_x15 = constants::get_namespace("x15"); - static const auto &xmlns_x15ac = constants::get_namespace("x15ac"); + static const auto &xmlns = constants::namespace_("workbook"); + static const auto &xmlns_r = constants::namespace_("r"); + static const auto &xmlns_s = constants::namespace_("spreadsheetml"); serializer().start_element(xmlns, "workbook"); serializer().namespace_decl(xmlns, ""); serializer().namespace_decl(xmlns_r, "r"); - if (source_.x15_enabled()) - { - serializer().namespace_decl(xmlns_mc, "mc"); - serializer().namespace_decl(xmlns_x15, "x15"); - serializer().attribute(xmlns_mc, "Ignorable", "x15"); - } - if (source_.has_file_version()) { serializer().start_element(xmlns, "fileVersion"); - serializer().attribute("appName", source_.get_app_name()); - serializer().attribute("lastEdited", source_.get_last_edited()); - serializer().attribute("lowestEdited", source_.get_lowest_edited()); - serializer().attribute("rupBuild", source_.get_rup_build()); + serializer().attribute("appName", source_.app_name()); + serializer().attribute("lastEdited", source_.last_edited()); + serializer().attribute("lowestEdited", source_.lowest_edited()); + serializer().attribute("rupBuild", source_.rup_build()); serializer().end_element(xmlns, "fileVersion"); } - if (source_.has_properties()) + if (source_.has_code_name() || source_.base_date() == calendar::mac_1904) { serializer().start_element(xmlns, "workbookPr"); if (source_.has_code_name()) { - serializer().attribute("codeName", source_.get_code_name()); + serializer().attribute("codeName", source_.code_name()); } - if (!skip_unknown_elements) + if (source_.base_date() == calendar::mac_1904) { - serializer().attribute("defaultThemeVersion", "124226"); - serializer().attribute("date1904", source_.get_base_date() == calendar::mac_1904 ? "1" : "0"); + serializer().attribute("date1904", "1"); } serializer().end_element(xmlns, "workbookPr"); } - if (source_.has_absolute_path()) - { - serializer().start_element(xmlns_mc, "AlternateContent"); - serializer().namespace_decl(xmlns_mc, "mc"); - - serializer().start_element(xmlns_mc, "Choice"); - serializer().attribute("Requires", "x15"); - - serializer().start_element(xmlns_x15ac, "absPath"); - serializer().namespace_decl(xmlns_x15ac, "x15ac"); - serializer().attribute("url", source_.get_absolute_path().string()); - serializer().end_element(xmlns_x15ac, "absPath"); - - serializer().end_element(xmlns_mc, "Choice"); - serializer().end_element(xmlns_mc, "AlternateContent"); - } - if (source_.has_view()) { serializer().start_element(xmlns, "bookViews"); serializer().start_element(xmlns, "workbookView"); - const auto &view = source_.get_view(); + const auto &view = source_.view(); - if (!skip_unknown_elements) - { - serializer().attribute("activeTab", "0"); - serializer().attribute("autoFilterDateGrouping", "1"); - serializer().attribute("firstSheet", "0"); - serializer().attribute("minimized", "0"); - serializer().attribute("showHorizontalScroll", "1"); - serializer().attribute("showSheetTabs", "1"); - serializer().attribute("showVerticalScroll", "1"); - serializer().attribute("tabRatio", "600"); - serializer().attribute("visibility", "visible"); - } + serializer().attribute("activeTab", "0"); + serializer().attribute("autoFilterDateGrouping", "1"); + serializer().attribute("firstSheet", "0"); + serializer().attribute("minimized", "0"); + serializer().attribute("showHorizontalScroll", "1"); + serializer().attribute("showSheetTabs", "1"); + serializer().attribute("showVerticalScroll", "1"); + serializer().attribute("visibility", "visible"); serializer().attribute("xWindow", view.x_window); serializer().attribute("yWindow", view.y_window); @@ -455,14 +446,14 @@ void xlsx_producer::write_workbook(const relationship &rel) #pragma clang diagnostic ignored "-Wrange-loop-analysis" for (const auto ws : source_) { - auto sheet_rel_id = source_.d_->sheet_title_rel_id_map_[ws.get_title()]; - auto sheet_rel = source_.d_->manifest_.get_relationship(rel.get_target().get_path(), sheet_rel_id); + auto sheet_rel_id = source_.d_->sheet_title_rel_id_map_[ws.title()]; + auto sheet_rel = source_.d_->manifest_.relationship(rel.target().path(), sheet_rel_id); serializer().start_element(xmlns, "sheet"); - serializer().attribute("name", ws.get_title()); - serializer().attribute("sheetId", ws.get_id()); + serializer().attribute("name", ws.title()); + serializer().attribute("sheetId", ws.id()); - if (ws.has_page_setup() && ws.get_sheet_state() == xlnt::sheet_state::hidden) + if (ws.has_page_setup() && ws.sheet_state() == xlnt::sheet_state::hidden) { serializer().attribute("state", "hidden"); } @@ -476,8 +467,8 @@ void xlsx_producer::write_workbook(const relationship &rel) serializer().attribute("name", "_xlnm._FilterDatabase"); serializer().attribute("hidden", write_bool(true)); serializer().attribute("localSheetId", "0"); - serializer().characters("'" + ws.get_title() + "'!" - + range_reference::make_absolute(ws.get_auto_filter()).to_string()); + serializer().characters("'" + ws.title() + "'!" + + range_reference::make_absolute(ws.auto_filter()).to_string()); serializer().end_element(xmlns, "definedName"); } @@ -488,32 +479,24 @@ void xlsx_producer::write_workbook(const relationship &rel) serializer().end_element(xmlns, "sheets"); - if (source_.has_calculation_properties()) - { - serializer().start_element(xmlns, "calcPr"); - serializer().attribute("calcId", 150000); - - if (!skip_unknown_elements) - { - serializer().attribute("calcMode", "auto"); - serializer().attribute("fullCalcOnLoad", "1"); - } - - serializer().attribute("concurrentCalc", "0"); - serializer().end_element(xmlns, "calcPr"); - } + serializer().start_element(xmlns, "calcPr"); + serializer().attribute("calcId", 150000); + serializer().attribute("calcMode", "auto"); + serializer().attribute("fullCalcOnLoad", "1"); + serializer().attribute("concurrentCalc", "0"); + serializer().end_element(xmlns, "calcPr"); - if (!source_.get_named_ranges().empty()) + if (!source_.named_ranges().empty()) { serializer().start_element(xmlns, "definedNames"); - for (auto &named_range : source_.get_named_ranges()) + for (auto &named_range : source_.named_ranges()) { serializer().start_element(xmlns_s, "definedName"); serializer().namespace_decl(xmlns_s, "s"); - serializer().attribute("name", named_range.get_name()); - const auto &target = named_range.get_targets().front(); - serializer().characters("'" + target.first.get_title() + serializer().attribute("name", named_range.name()); + const auto &target = named_range.targets().front(); + serializer().characters("'" + target.first.title() + "\'!" + target.second.to_string()); serializer().end_element(xmlns_s, "definedName"); } @@ -521,108 +504,95 @@ void xlsx_producer::write_workbook(const relationship &rel) serializer().end_element(xmlns, "definedNames"); } - if (source_.has_arch_id()) - { - serializer().start_element(xmlns, "extLst"); - serializer().start_element(xmlns, "ext"); - serializer().namespace_decl(xmlns_mx, "mx"); - serializer().attribute("uri", "{7523E5D3-25F3-A5E0-1632-64F254C22452}"); - serializer().start_element(xmlns_mx, "ArchID"); - serializer().attribute("Flags", 2); - serializer().end_element(xmlns_mx, "ArchID"); - serializer().end_element(xmlns, "ext"); - serializer().end_element(xmlns, "extLst"); - } - serializer().end_element(xmlns, "workbook"); - auto workbook_rels = source_.get_manifest().get_relationships(rel.get_target().get_path()); - write_relationships(workbook_rels, rel.get_target().get_path()); + auto workbook_rels = source_.manifest().relationships(rel.target().path()); + write_relationships(workbook_rels, rel.target().path()); for (const auto &child_rel : workbook_rels) { - path archive_path(child_rel.get_source().get_path().parent().append(child_rel.get_target().get_path())); + path archive_path(child_rel.source().path().parent().append(child_rel.target().path())); begin_part(archive_path); - switch (child_rel.get_type()) + switch (child_rel.type()) { - case relationship::type::calculation_chain: + case relationship_type::calculation_chain: write_calculation_chain(child_rel); break; - case relationship::type::chartsheet: + case relationship_type::chartsheet: write_chartsheet(child_rel); break; - case relationship::type::connections: + case relationship_type::connections: write_connections(child_rel); break; - case relationship::type::custom_xml_mappings: + case relationship_type::custom_xml_mappings: write_custom_xml_mappings(child_rel); break; - case relationship::type::dialogsheet: + case relationship_type::dialogsheet: write_dialogsheet(child_rel); break; - case relationship::type::external_workbook_references: + case relationship_type::external_workbook_references: write_external_workbook_references(child_rel); break; - case relationship::type::metadata: + case relationship_type::metadata: write_metadata(child_rel); break; - case relationship::type::pivot_table: + case relationship_type::pivot_table: write_pivot_table(child_rel); break; - case relationship::type::shared_string_table: + case relationship_type::shared_string_table: write_shared_string_table(child_rel); break; - case relationship::type::shared_workbook_revision_headers: + case relationship_type::shared_workbook_revision_headers: write_shared_workbook_revision_headers(child_rel); break; - case relationship::type::stylesheet: + case relationship_type::stylesheet: write_styles(child_rel); break; - case relationship::type::theme: + case relationship_type::theme: write_theme(child_rel); break; - case relationship::type::volatile_dependencies: + case relationship_type::volatile_dependencies: write_volatile_dependencies(child_rel); break; - case relationship::type::worksheet: + case relationship_type::worksheet: write_worksheet(child_rel); break; - case relationship::type::office_document: break; - case relationship::type::thumbnail: break; - case relationship::type::extended_properties: break; - case relationship::type::core_properties: break; - case relationship::type::hyperlink: break; - case relationship::type::comments: break; - case relationship::type::vml_drawing: break; - case relationship::type::unknown: break; - case relationship::type::custom_properties: break; - case relationship::type::printer_settings: break; - case relationship::type::custom_property: break; - case relationship::type::drawings: break; - case relationship::type::pivot_table_cache_definition: break; - case relationship::type::pivot_table_cache_records: break; - case relationship::type::query_table: break; - case relationship::type::shared_workbook: break; - case relationship::type::revision_log: break; - case relationship::type::shared_workbook_user_data: break; - case relationship::type::single_cell_table_definitions: break; - case relationship::type::table_definition: break; - case relationship::type::image: break; + case relationship_type::office_document: break; + case relationship_type::thumbnail: break; + case relationship_type::extended_properties: break; + case relationship_type::core_properties: break; + case relationship_type::hyperlink: break; + case relationship_type::comments: break; + case relationship_type::vml_drawing: break; + case relationship_type::unknown: break; + case relationship_type::custom_properties: break; + case relationship_type::printer_settings: break; + case relationship_type::custom_property: break; + case relationship_type::drawings: break; + case relationship_type::pivot_table_cache_definition: break; + case relationship_type::pivot_table_cache_records: break; + case relationship_type::query_table: break; + case relationship_type::shared_workbook: break; + case relationship_type::revision_log: break; + case relationship_type::shared_workbook_user_data: break; + case relationship_type::single_cell_table_definitions: break; + case relationship_type::table_definition: break; + case relationship_type::image: break; } } } @@ -671,7 +641,7 @@ void xlsx_producer::write_pivot_table(const relationship &/*rel*/) void xlsx_producer::write_shared_string_table(const relationship &/*rel*/) { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); serializer().start_element(xmlns, "sst"); serializer().namespace_decl(xmlns, ""); @@ -685,16 +655,16 @@ void xlsx_producer::write_shared_string_table(const relationship &/*rel*/) { auto dimension = ws.calculate_dimension(); - for (xlnt::row_t row = dimension.get_top_left().get_row(); - row <= dimension.get_bottom_right().get_row(); ++row) + for (xlnt::row_t row = dimension.top_left().row(); + row <= dimension.bottom_right().row(); ++row) { - for (xlnt::column_t column = dimension.get_top_left().get_column(); - column <= dimension.get_bottom_right().get_column(); ++column) + for (xlnt::column_t column = dimension.top_left().column(); + column <= dimension.bottom_right().column(); ++column) { if (ws.has_cell(xlnt::cell_reference(column, row))) { - string_count += (ws.get_cell(xlnt::cell_reference(column, row)) - .get_data_type() == cell::type::string) ? 1 : 0; + string_count += (ws.cell(xlnt::cell_reference(column, row)) + .data_type() == cell::type::string) ? 1 : 0; } } } @@ -702,9 +672,9 @@ void xlsx_producer::write_shared_string_table(const relationship &/*rel*/) #pragma clang diagnostic pop serializer().attribute("count", string_count); - serializer().attribute("uniqueCount", source_.get_shared_strings().size()); + serializer().attribute("uniqueCount", source_.shared_strings().size()); - for (const auto &string : source_.get_shared_strings()) + for (const auto &string : source_.shared_strings()) { if (string.runs().size() == 1 && !string.runs().at(0).has_formatting()) { @@ -728,39 +698,39 @@ void xlsx_producer::write_shared_string_table(const relationship &/*rel*/) if (run.has_size()) { serializer().start_element(xmlns, "sz"); - serializer().attribute("val", run.get_size()); + serializer().attribute("val", run.size()); serializer().end_element(xmlns, "sz"); } if (run.has_color()) { serializer().start_element(xmlns, "color"); - write_color(run.get_color()); + write_color(run.color()); serializer().end_element(xmlns, "color"); } if (run.has_font()) { serializer().start_element(xmlns, "rFont"); - serializer().attribute("val", run.get_font()); + serializer().attribute("val", run.font()); serializer().end_element(xmlns, "rFont"); } if (run.has_family()) { serializer().start_element(xmlns, "family"); - serializer().attribute("val", run.get_family()); + serializer().attribute("val", run.family()); serializer().end_element(xmlns, "family"); } if (run.has_scheme()) { serializer().start_element(xmlns, "scheme"); - serializer().attribute("val", run.get_scheme()); + serializer().attribute("val", run.scheme()); serializer().end_element(xmlns, "scheme"); } - if (run.bold_set()) + if (run.bold()) { serializer().start_element(xmlns, "b"); serializer().end_element(xmlns, "b"); @@ -769,7 +739,7 @@ void xlsx_producer::write_shared_string_table(const relationship &/*rel*/) serializer().end_element(xmlns, "rPr"); } - serializer().element(xmlns, "t", run.get_string()); + serializer().element(xmlns, "t", run.string()); serializer().end_element(xmlns, "r"); } @@ -796,22 +766,12 @@ void xlsx_producer::write_shared_workbook_user_data(const relationship &/*rel*/) void xlsx_producer::write_styles(const relationship &/*rel*/) { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - static const auto &xmlns_x14 = constants::get_namespace("x14"); - static const auto &xmlns_x14ac = constants::get_namespace("x14ac"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); serializer().start_element(xmlns, "styleSheet"); serializer().namespace_decl(xmlns, ""); - if (source_.x15_enabled()) - { - serializer().namespace_decl(xmlns_mc, "mc"); - serializer().namespace_decl(xmlns_x14ac, "x14ac"); - serializer().attribute(xmlns_mc, "Ignorable", "x14ac"); - } - - const auto &stylesheet = source_.impl().stylesheet_; + const auto &stylesheet = source_.impl().stylesheet_.get(); // Number Formats @@ -820,17 +780,17 @@ void xlsx_producer::write_styles(const relationship &/*rel*/) const auto &number_formats = stylesheet.number_formats; auto num_custom = std::count_if(number_formats.begin(), number_formats.end(), - [](const number_format &nf) { return nf.get_id() >= 164; }); + [](const number_format &nf) { return nf.id() >= 164; }); serializer().start_element(xmlns, "numFmts"); serializer().attribute("count", num_custom); for (const auto &num_fmt : number_formats) { - if (num_fmt.get_id() < 164) continue; + if (num_fmt.id() < 164) continue; serializer().start_element(xmlns, "numFmt"); - serializer().attribute("numFmtId", num_fmt.get_id()); - serializer().attribute("formatCode", num_fmt.get_format_string()); + serializer().attribute("numFmtId", num_fmt.id()); + serializer().attribute("formatCode", num_fmt.format_string()); serializer().end_element(xmlns, "numFmt"); } @@ -846,21 +806,6 @@ void xlsx_producer::write_styles(const relationship &/*rel*/) serializer().start_element(xmlns, "fonts"); serializer().attribute("count", fonts.size()); - auto num_known_fonts = std::count_if(fonts.begin(), fonts.end(), [](const xlnt::font &f) - { - static const auto known_fonts = new std::vector - { - xlnt::font().color(xlnt::theme_color(1)).scheme("minor").family(2) - }; - - return std::find(known_fonts->begin(), known_fonts->end(), f) != known_fonts->end(); - }); - - if (source_.x15_enabled()) - { - serializer().attribute(xmlns_x14ac, "knownFonts", num_known_fonts); - } - for (const auto ¤t_font : fonts) { serializer().start_element(xmlns, "font"); @@ -897,10 +842,10 @@ void xlsx_producer::write_styles(const relationship &/*rel*/) serializer().attribute("val", current_font.size()); serializer().end_element(xmlns, "sz"); - if (current_font.color()) + if (current_font.has_color()) { serializer().start_element(xmlns, "color"); - write_color(*current_font.color()); + write_color(current_font.color()); serializer().end_element(xmlns, "color"); } @@ -908,17 +853,17 @@ void xlsx_producer::write_styles(const relationship &/*rel*/) serializer().attribute("val", current_font.name()); serializer().end_element(xmlns, "name"); - if (current_font.family()) + if (current_font.has_family()) { serializer().start_element(xmlns, "family"); - serializer().attribute("val", *current_font.family()); + serializer().attribute("val", current_font.family()); serializer().end_element(xmlns, "family"); } - if (current_font.scheme()) + if (current_font.has_scheme()) { serializer().start_element(xmlns, "scheme"); - serializer().attribute("val", *current_font.scheme()); + serializer().attribute("val", current_font.scheme()); serializer().end_element(xmlns, "scheme"); } @@ -1328,35 +1273,27 @@ void xlsx_producer::write_styles(const relationship &/*rel*/) if (!stylesheet.colors.empty()) { + serializer().start_element(xmlns, "colors"); serializer().start_element(xmlns, "indexedColors"); for (auto &c : stylesheet.colors) { serializer().start_element(xmlns, "rgbColor"); - serializer().attribute("rgb", c.get_rgb().get_hex_string()); + serializer().attribute("rgb", c.rgb().hex_string()); serializer().end_element(xmlns, "rgbColor"); } serializer().end_element(xmlns, "indexedColors"); + serializer().end_element(xmlns, "colors"); } - - serializer().start_element(xmlns, "extLst"); - serializer().start_element(xmlns, "ext"); - serializer().namespace_decl(xmlns_x14, "x14"); - serializer().attribute("uri", "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"); - serializer().start_element(xmlns_x14, "slicerStyles"); - serializer().attribute("defaultSlicerStyle", "SlicerStyleLight1"); - serializer().end_element(xmlns_x14, "slicerStyles"); - serializer().end_element(xmlns, "ext"); - serializer().end_element(xmlns, "extLst"); serializer().end_element(xmlns, "styleSheet"); } -void xlsx_producer::write_theme(const relationship &/*rel*/) +void xlsx_producer::write_theme(const relationship &theme_rel) { - static const auto &xmlns_a = constants::get_namespace("drawingml"); - static const auto &xmlns_thm15 = constants::get_namespace("thm15"); + static const auto &xmlns_a = constants::namespace_("drawingml"); + static const auto &xmlns_thm15 = constants::namespace_("thm15"); serializer().start_element(xmlns_a, "theme"); serializer().namespace_decl(xmlns_a, "a"); @@ -1821,6 +1758,24 @@ void xlsx_producer::write_theme(const relationship &/*rel*/) serializer().end_element(xmlns_a, "extLst"); serializer().end_element(xmlns_a, "theme"); + + const auto workbook_rel = source_.manifest().relationship(path("/"), relationship_type::office_document); + const auto theme_part = source_.manifest().canonicalize({workbook_rel, theme_rel}); + const auto theme_rels = source_.manifest().relationships(theme_part); + + if (!theme_rels.empty()) + { + write_relationships(theme_rels, theme_part); + + for (auto rel : theme_rels) + { + if (rel.type() == relationship_type::image) + { + const auto image_path = source_.manifest().canonicalize({workbook_rel, theme_rel, rel}); + write_image(image_path); + } + } + } } void xlsx_producer::write_volatile_dependencies(const relationship &/*rel*/) @@ -1830,34 +1785,25 @@ void xlsx_producer::write_volatile_dependencies(const relationship &/*rel*/) void xlsx_producer::write_worksheet(const relationship &rel) { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); - static const auto &xmlns_r = constants::get_namespace("r"); - static const auto &xmlns_mc = constants::get_namespace("mc"); - static const auto &xmlns_x14ac = constants::get_namespace("x14ac"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); + static const auto &xmlns_r = constants::namespace_("r"); - auto worksheet_part = rel.get_source().get_path().parent().append(rel.get_target().get_path()); - auto worksheet_rels = source_.get_manifest().get_relationships(worksheet_part); + auto worksheet_part = rel.source().path().parent().append(rel.target().path()); + auto worksheet_rels = source_.manifest().relationships(worksheet_part); auto title = std::find_if(source_.d_->sheet_title_rel_id_map_.begin(), source_.d_->sheet_title_rel_id_map_.end(), [&](const std::pair &p) { - return p.second == rel.get_id(); + return p.second == rel.id(); })->first; - auto ws = source_.get_sheet_by_title(title); + auto ws = source_.sheet_by_title(title); serializer().start_element(xmlns, "worksheet"); serializer().namespace_decl(xmlns, ""); serializer().namespace_decl(xmlns_r, "r"); - if (ws.x14ac_enabled()) - { - serializer().namespace_decl(xmlns_mc, "mc"); - serializer().namespace_decl(xmlns_x14ac, "x14ac"); - serializer().attribute(xmlns_mc, "Ignorable", "x14ac"); - } - if (ws.has_page_setup()) { serializer().start_element(xmlns, "sheetPr"); @@ -1868,7 +1814,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().end_element(xmlns, "outlinePr"); serializer().start_element(xmlns, "pageSetUpPr"); - serializer().attribute("fitToPage", write_bool(ws.get_page_setup().fit_to_page())); + serializer().attribute("fitToPage", write_bool(ws.page_setup().fit_to_page())); serializer().end_element(xmlns, "pageSetUpPr"); serializer().end_element(xmlns, "sheetPr"); @@ -1879,7 +1825,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().start_element(xmlns, "dimension"); const auto dimension = ws.calculate_dimension(); serializer().attribute("ref", dimension.is_single_cell() - ? dimension.get_top_left().to_string() : dimension.to_string()); + ? dimension.top_left().to_string() : dimension.to_string()); serializer().end_element(xmlns, "dimension"); } @@ -1888,77 +1834,58 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().start_element(xmlns, "sheetViews"); serializer().start_element(xmlns, "sheetView"); - const auto view = ws.get_view(); + const auto view = ws.view(); - serializer().attribute("tabSelected", "1"); - serializer().attribute("workbookViewId", "0"); + serializer().attribute("tabSelected", write_bool(view.id() == 0)); + serializer().attribute("workbookViewId", view.id()); - if (!view.get_selections().empty() && !ws.has_frozen_panes()) + if (view.has_pane()) { - serializer().start_element(xmlns, "selection"); + const auto ¤t_pane = view.pane(); + serializer().start_element(xmlns, "pane"); // CT_Pane - const auto &first_selection = view.get_selections().front(); + if (current_pane.top_left_cell.is_set()) + { + serializer().attribute("topLeftCell", current_pane.top_left_cell.get().to_string()); + } - if (first_selection.has_active_cell()) - { - auto active_cell = first_selection.get_active_cell(); - serializer().attribute("activeCell", active_cell.to_string()); - serializer().attribute("sqref", active_cell.to_string()); - } - - serializer().end_element(xmlns, "selection"); + serializer().attribute("xSplit", current_pane.x_split.index); + serializer().attribute("ySplit", current_pane.y_split); + + if (current_pane.active_pane != pane_corner::top_left) + { + serializer().attribute("activePane", current_pane.active_pane); + } + + if (current_pane.state != pane_state::split) + { + serializer().attribute("state", current_pane.state); + } + + serializer().end_element(xmlns, "pane"); } - auto active_pane = "bottomRight"s; - - if (ws.has_frozen_panes()) + for (const auto ¤t_selection : view.selections()) { - serializer().start_element(xmlns, "pane"); + serializer().start_element(xmlns, "selection"); // CT_Selection - if (ws.get_frozen_panes().get_column_index() > 1) + if (current_selection.has_active_cell()) { - serializer().attribute("xSplit", ws.get_frozen_panes().get_column_index().index - 1); - active_pane = "topRight"; + serializer().attribute("activeCell", current_selection.active_cell().to_string()); + serializer().attribute("sqref", current_selection.active_cell().to_string()); } - - if (ws.get_frozen_panes().get_row() > 1) - { - serializer().attribute("ySplit", ws.get_frozen_panes().get_row() - 1); - active_pane = "bottomLeft"; - } - /* - if (ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1) - { - serializer().start_element(xmlns, "selection"); - serializer().attribute("pane", "topRight"); - auto bottom_left_node = sheet_view_node.append_child("selection"); - serializer().attribute("pane", "bottomLeft"); - active_pane = "bottomRight"; - } - */ + if (current_selection.sqref() != "A1:A1") + { + serializer().attribute("sqref", current_selection.sqref().to_string()); + } +*/ + if (current_selection.pane() != pane_corner::top_left) + { + serializer().attribute("pane", current_selection.pane()); + } - serializer().attribute("topLeftCell", ws.get_frozen_panes().to_string()); - serializer().attribute("activePane", active_pane); - serializer().attribute("state", "frozen"); - - serializer().start_element(xmlns, "selection"); - - if (ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1) - { - serializer().attribute("pane", "bottomRight"); - } - else if (ws.get_frozen_panes().get_row() > 1) - { - serializer().attribute("pane", "bottomLeft"); - } - else if (ws.get_frozen_panes().get_column_index() > 1) - { - serializer().attribute("pane", "topRight"); - } - serializer().end_element(xmlns, "selection"); - serializer().end_element(xmlns, "pane"); } serializer().end_element(xmlns, "sheetView"); @@ -1970,16 +1897,12 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().start_element(xmlns, "sheetFormatPr"); serializer().attribute("baseColWidth", "10"); serializer().attribute("defaultRowHeight", "16"); - if (ws.x14ac_enabled()) - { - serializer().attribute(xmlns_x14ac, "dyDescent", "0.2"); - } serializer().end_element(xmlns, "sheetFormatPr"); } bool has_column_properties = false; - for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); column++) + for (auto column = ws.lowest_column(); column <= ws.highest_column(); column++) { if (ws.has_column_properties(column)) { @@ -1992,11 +1915,11 @@ void xlsx_producer::write_worksheet(const relationship &rel) { serializer().start_element(xmlns, "cols"); - for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); column++) + for (auto column = ws.lowest_column(); column <= ws.highest_column(); column++) { if (!ws.has_column_properties(column)) continue; - const auto &props = ws.get_column_properties(column); + const auto &props = ws.column_properties(column); serializer().start_element(xmlns, "col"); serializer().attribute("min", column.index); @@ -2010,22 +1933,30 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().end_element(xmlns, "cols"); } + const auto hyperlink_rels = source_.manifest().relationships(worksheet_part, relationship_type::hyperlink); + std::unordered_map reverse_hyperlink_references; + + for (auto hyperlink_rel : hyperlink_rels) + { + reverse_hyperlink_references[hyperlink_rel.target().path().string()] = rel.id(); + } + std::unordered_map hyperlink_references; serializer().start_element(xmlns, "sheetData"); - const auto &shared_strings = ws.get_workbook().get_shared_strings(); + const auto &shared_strings = ws.workbook().shared_strings(); std::vector cells_with_comments; for (auto row : ws.rows()) { - auto min = static_cast(row.num_cells()); + auto min = static_cast(row.length()); xlnt::row_t max = 0; bool any_non_null = false; for (auto cell : row) { - min = std::min(min, cell.get_column().index); - max = std::max(max, cell.get_column().index); + min = std::min(min, cell.column().index); + max = std::max(max, cell.column().index); if (!cell.garbage_collectible()) { @@ -2040,13 +1971,13 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().start_element(xmlns, "row"); - serializer().attribute("r", row.front().get_row()); + serializer().attribute("r", row.front().row()); serializer().attribute("spans", std::to_string(min) + ":" + std::to_string(max)); - if (ws.has_row_properties(row.front().get_row())) + if (ws.has_row_properties(row.front().row())) { serializer().attribute("customHeight", "1"); - auto height = ws.get_row_properties(row.front().get_row()).height; + auto height = ws.row_properties(row.front().row()).height; if (std::fabs(height - std::floor(height)) == 0.L) { @@ -2058,34 +1989,34 @@ void xlsx_producer::write_worksheet(const relationship &rel) } } - if (!skip_unknown_elements) - { - serializer().attribute(xmlns_x14ac, "dyDescent", 0.25); - } - for (auto cell : row) { if (cell.has_comment()) { - cells_with_comments.push_back(cell.get_reference()); + cells_with_comments.push_back(cell.reference()); } if (!cell.garbage_collectible()) { serializer().start_element(xmlns, "c"); - serializer().attribute("r", cell.get_reference().to_string()); + serializer().attribute("r", cell.reference().to_string()); if (cell.has_format()) { serializer().attribute("s", cell.format().id()); } - if (cell.get_data_type() == cell::type::string) + if (cell.has_hyperlink()) + { + hyperlink_references[cell.reference().to_string()] = reverse_hyperlink_references[cell.hyperlink()]; + } + + if (cell.data_type() == cell::type::string) { if (cell.has_formula()) { serializer().attribute("t", "str"); - serializer().element(xmlns, "f", cell.get_formula()); + serializer().element(xmlns, "f", cell.formula()); serializer().element(xmlns, "v", cell.to_string()); serializer().end_element(xmlns, "c"); @@ -2096,7 +2027,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) for (std::size_t i = 0; i < shared_strings.size(); i++) { - if (shared_strings[i] == cell.get_value()) + if (shared_strings[i] == cell.value()) { match_index = static_cast(i); break; @@ -2105,7 +2036,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) if (match_index == -1) { - if (cell.get_value().empty()) + if (cell.value().empty()) { serializer().attribute("t", "s"); } @@ -2113,7 +2044,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) { serializer().attribute("t", "inlineStr"); serializer().start_element(xmlns, "is"); - serializer().element(xmlns, "t", cell.get_value()); + serializer().element(xmlns, "t", cell.value()); serializer().end_element(xmlns, "is"); } } @@ -2125,18 +2056,18 @@ void xlsx_producer::write_worksheet(const relationship &rel) } else { - if (cell.get_data_type() != cell::type::null) + if (cell.data_type() != cell::type::null) { - if (cell.get_data_type() == cell::type::boolean) + if (cell.data_type() == cell::type::boolean) { serializer().attribute("t", "b"); - serializer().element(xmlns, "v", write_bool(cell.get_value())); + serializer().element(xmlns, "v", write_bool(cell.value())); } - else if (cell.get_data_type() == cell::type::numeric) + else if (cell.data_type() == cell::type::numeric) { if (cell.has_formula()) { - serializer().element(xmlns, "f", cell.get_formula()); + serializer().element(xmlns, "f", cell.formula()); serializer().element(xmlns, "v", cell.to_string()); serializer().end_element(xmlns, "c"); @@ -2146,15 +2077,15 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().attribute("t", "n"); serializer().start_element(xmlns, "v"); - if (is_integral(cell.get_value())) + if (is_integral(cell.value())) { - serializer().characters(cell.get_value()); + serializer().characters(cell.value()); } else { std::stringstream ss; ss.precision(20); - ss << cell.get_value(); + ss << cell.value(); ss.str(); serializer().characters(ss.str()); } @@ -2164,7 +2095,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) } else if (cell.has_formula()) { - serializer().element(xmlns, "f", cell.get_formula()); + serializer().element(xmlns, "f", cell.formula()); // todo (but probably not) could calculate the formula and set the value here serializer().end_element(xmlns, "c"); @@ -2184,16 +2115,16 @@ void xlsx_producer::write_worksheet(const relationship &rel) if (ws.has_auto_filter()) { serializer().start_element(xmlns, "autoFilter"); - serializer().attribute("ref", ws.get_auto_filter().to_string()); + serializer().attribute("ref", ws.auto_filter().to_string()); serializer().end_element(xmlns, "autoFilter"); } - if (!ws.get_merged_ranges().empty()) + if (!ws.merged_ranges().empty()) { serializer().start_element(xmlns, "mergeCells"); - serializer().attribute("count", ws.get_merged_ranges().size()); + serializer().attribute("count", ws.merged_ranges().size()); - for (auto merged_range : ws.get_merged_ranges()) + for (auto merged_range : ws.merged_ranges()) { serializer().start_element(xmlns, "mergeCell"); serializer().attribute("ref", merged_range.to_string()); @@ -2203,40 +2134,26 @@ void xlsx_producer::write_worksheet(const relationship &rel) serializer().end_element(xmlns, "mergeCells"); } - if (!worksheet_rels.empty()) + if (!hyperlink_rels.empty()) { - std::vector hyperlink_sheet_rels; + serializer().start_element(xmlns, "hyperlinks"); - for (const auto &sheet_rel : worksheet_rels) - { - if (sheet_rel.get_type() == relationship::type::hyperlink) - { - hyperlink_sheet_rels.push_back(sheet_rel); - } - } - - if (!hyperlink_sheet_rels.empty()) - { - serializer().start_element(xmlns, "hyperlinks"); - - for (const auto &hyperlink_rel : hyperlink_sheet_rels) - { - serializer().start_element(xmlns, "hyperlink"); - serializer().attribute("display", hyperlink_rel.get_target().get_path().string()); - serializer().attribute("ref", hyperlink_references.at(hyperlink_rel.get_id())); - serializer().attribute(xmlns_r, "id", hyperlink_rel.get_id()); - serializer().end_element(xmlns, "hyperlink"); - } - - serializer().end_element(xmlns, "hyperlinks"); - } + for (const auto &hyperlink : hyperlink_references) + { + serializer().start_element(xmlns, "hyperlink"); + serializer().attribute("ref", hyperlink.first); + serializer().attribute(xmlns_r, "id", hyperlink.second); + serializer().end_element(xmlns, "hyperlink"); + } + + serializer().end_element(xmlns, "hyperlinks"); } if (ws.has_page_setup()) { serializer().start_element(xmlns, "printOptions"); - serializer().attribute("horizontalCentered", write_bool(ws.get_page_setup().get_horizontal_centered())); - serializer().attribute("verticalCentered", write_bool(ws.get_page_setup().get_vertical_centered())); + serializer().attribute("horizontalCentered", write_bool(ws.page_setup().horizontal_centered())); + serializer().attribute("verticalCentered", write_bool(ws.page_setup().vertical_centered())); serializer().end_element(xmlns, "printOptions"); } @@ -2266,12 +2183,12 @@ void xlsx_producer::write_worksheet(const relationship &rel) return n.substr(0, index + 1); }; - serializer().attribute("left", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_left()))); - serializer().attribute("right", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_right()))); - serializer().attribute("top", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_top()))); - serializer().attribute("bottom", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_bottom()))); - serializer().attribute("header", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_header()))); - serializer().attribute("footer", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_footer()))); + serializer().attribute("left", remove_trailing_zeros(std::to_string(ws.page_margins().left()))); + serializer().attribute("right", remove_trailing_zeros(std::to_string(ws.page_margins().right()))); + serializer().attribute("top", remove_trailing_zeros(std::to_string(ws.page_margins().top()))); + serializer().attribute("bottom", remove_trailing_zeros(std::to_string(ws.page_margins().bottom()))); + serializer().attribute("header", remove_trailing_zeros(std::to_string(ws.page_margins().header()))); + serializer().attribute("footer", remove_trailing_zeros(std::to_string(ws.page_margins().footer()))); serializer().end_element(xmlns, "pageMargins"); } @@ -2280,15 +2197,15 @@ void xlsx_producer::write_worksheet(const relationship &rel) { serializer().start_element(xmlns, "pageSetup"); serializer().attribute("orientation", - ws.get_page_setup().get_orientation() == xlnt::orientation::landscape + ws.page_setup().orientation() == xlnt::orientation::landscape ? "landscape" : "portrait"); - serializer().attribute("paperSize", static_cast(ws.get_page_setup().get_paper_size())); - serializer().attribute("fitToHeight", write_bool(ws.get_page_setup().fit_to_height())); - serializer().attribute("fitToWidth", write_bool(ws.get_page_setup().fit_to_width())); + serializer().attribute("paperSize", static_cast(ws.page_setup().paper_size())); + serializer().attribute("fitToHeight", write_bool(ws.page_setup().fit_to_height())); + serializer().attribute("fitToWidth", write_bool(ws.page_setup().fit_to_width())); serializer().end_element(xmlns, "pageSetup"); } - if (!ws.get_header_footer().is_default()) + if (!ws.header_footer().is_default()) { // todo: this shouldn't be hardcoded static const auto header_text = new std::string( @@ -2309,10 +2226,10 @@ void xlsx_producer::write_worksheet(const relationship &rel) { for (const auto &child_rel : worksheet_rels) { - if (child_rel.get_type() == xlnt::relationship_type::vml_drawing) + if (child_rel.type() == xlnt::relationship_type::vml_drawing) { serializer().start_element(xmlns, "legacyDrawing"); - serializer().attribute(xml::qname(xmlns_r, "id"), child_rel.get_id()); + serializer().attribute(xml::qname(xmlns_r, "id"), child_rel.id()); serializer().end_element(xmlns, "legacyDrawing"); //todo: there's only one of these per sheet, right? @@ -2329,7 +2246,10 @@ void xlsx_producer::write_worksheet(const relationship &rel) for (const auto &child_rel : worksheet_rels) { - path archive_path(worksheet_part.parent().append(child_rel.get_target().get_path())); + if (child_rel.target_mode() == target_mode::external) continue; + + // todo: this is ugly + path archive_path(worksheet_part.parent().append(child_rel.target().path())); auto split_part_path = archive_path.split(); auto part_path_iter = split_part_path.begin(); while (part_path_iter != split_part_path.end()) @@ -2347,49 +2267,49 @@ void xlsx_producer::write_worksheet(const relationship &rel) begin_part(archive_path); - switch (child_rel.get_type()) + switch (child_rel.type()) { - case relationship::type::comments: + case relationship_type::comments: write_comments(child_rel, ws, cells_with_comments); break; - case relationship::type::vml_drawing: + case relationship_type::vml_drawing: write_vml_drawings(child_rel, ws, cells_with_comments); break; - case relationship::type::office_document: break; - case relationship::type::thumbnail: break; - case relationship::type::calculation_chain: break; - case relationship::type::extended_properties: break; - case relationship::type::core_properties: break; - case relationship::type::worksheet: break; - case relationship::type::shared_string_table: break; - case relationship::type::stylesheet: break; - case relationship::type::theme: break; - case relationship::type::hyperlink: break; - case relationship::type::chartsheet: break; - case relationship::type::unknown: break; - case relationship::type::custom_properties: break; - case relationship::type::printer_settings: break; - case relationship::type::connections: break; - case relationship::type::custom_property: break; - case relationship::type::custom_xml_mappings: break; - case relationship::type::dialogsheet: break; - case relationship::type::drawings: break; - case relationship::type::external_workbook_references: break; - case relationship::type::metadata: break; - case relationship::type::pivot_table: break; - case relationship::type::pivot_table_cache_definition: break; - case relationship::type::pivot_table_cache_records: break; - case relationship::type::query_table: break; - case relationship::type::shared_workbook_revision_headers: break; - case relationship::type::shared_workbook: break; - case relationship::type::revision_log: break; - case relationship::type::shared_workbook_user_data: break; - case relationship::type::single_cell_table_definitions: break; - case relationship::type::table_definition: break; - case relationship::type::volatile_dependencies: break; - case relationship::type::image: break; + case relationship_type::office_document: break; + case relationship_type::thumbnail: break; + case relationship_type::calculation_chain: break; + case relationship_type::extended_properties: break; + case relationship_type::core_properties: break; + case relationship_type::worksheet: break; + case relationship_type::shared_string_table: break; + case relationship_type::stylesheet: break; + case relationship_type::theme: break; + case relationship_type::hyperlink: break; + case relationship_type::chartsheet: break; + case relationship_type::unknown: break; + case relationship_type::custom_properties: break; + case relationship_type::printer_settings: break; + case relationship_type::connections: break; + case relationship_type::custom_property: break; + case relationship_type::custom_xml_mappings: break; + case relationship_type::dialogsheet: break; + case relationship_type::drawings: break; + case relationship_type::external_workbook_references: break; + case relationship_type::metadata: break; + case relationship_type::pivot_table: break; + case relationship_type::pivot_table_cache_definition: break; + case relationship_type::pivot_table_cache_records: break; + case relationship_type::query_table: break; + case relationship_type::shared_workbook_revision_headers: break; + case relationship_type::shared_workbook: break; + case relationship_type::revision_log: break; + case relationship_type::shared_workbook_user_data: break; + case relationship_type::single_cell_table_definitions: break; + case relationship_type::table_definition: break; + case relationship_type::volatile_dependencies: break; + case relationship_type::image: break; } } } @@ -2400,7 +2320,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) void xlsx_producer::write_comments(const relationship &/*rel*/, worksheet ws, const std::vector &cells) { - static const auto &xmlns = constants::get_namespace("spreadsheetml"); + static const auto &xmlns = constants::namespace_("spreadsheetml"); serializer().start_element(xmlns, "comments"); serializer().namespace_decl(xmlns, ""); @@ -2411,7 +2331,7 @@ void xlsx_producer::write_comments(const relationship &/*rel*/, worksheet ws, for (auto cell_ref : cells) { - auto cell = ws.get_cell(cell_ref); + auto cell = ws.cell(cell_ref); auto author = cell.comment().author(); if (authors.find(author) == authors.end()) @@ -2436,7 +2356,7 @@ void xlsx_producer::write_comments(const relationship &/*rel*/, worksheet ws, { serializer().start_element(xmlns, "comment"); - auto cell = ws.get_cell(cell_ref); + auto cell = ws.cell(cell_ref); auto cell_comment = cell.comment(); serializer().attribute("ref", cell_ref.to_string()); @@ -2455,39 +2375,39 @@ void xlsx_producer::write_comments(const relationship &/*rel*/, worksheet ws, if (run.has_size()) { serializer().start_element(xmlns, "sz"); - serializer().attribute("val", run.get_size()); + serializer().attribute("val", run.size()); serializer().end_element(xmlns, "sz"); } if (run.has_color()) { serializer().start_element(xmlns, "color"); - write_color(run.get_color()); + write_color(run.color()); serializer().end_element(xmlns, "color"); } if (run.has_font()) { serializer().start_element(xmlns, "rFont"); - serializer().attribute("val", run.get_font()); + serializer().attribute("val", run.font()); serializer().end_element(xmlns, "rFont"); } if (run.has_family()) { serializer().start_element(xmlns, "family"); - serializer().attribute("val", run.get_family()); + serializer().attribute("val", run.family()); serializer().end_element(xmlns, "family"); } if (run.has_scheme()) { serializer().start_element(xmlns, "scheme"); - serializer().attribute("val", run.get_scheme()); + serializer().attribute("val", run.scheme()); serializer().end_element(xmlns, "scheme"); } - if (run.bold_set()) + if (run.bold()) { serializer().start_element(xmlns, "b"); serializer().end_element(xmlns, "b"); @@ -2496,7 +2416,7 @@ void xlsx_producer::write_comments(const relationship &/*rel*/, worksheet ws, serializer().end_element(xmlns, "rPr"); } - serializer().element(xmlns, "t", run.get_string()); + serializer().element(xmlns, "t", run.string()); serializer().end_element(xmlns, "r"); } @@ -2529,7 +2449,7 @@ void xlsx_producer::write_vml_drawings(const relationship &rel, worksheet ws, serializer().start_element(xmlns_o, "idmap"); serializer().attribute(xml::qname(xmlns_v, "ext"), "edit"); - auto filename = rel.get_target().get_path().split_extension().first; + auto filename = rel.target().path().split_extension().first; auto index_pos = filename.size() - 1; while (filename[index_pos] >= '0' && filename[index_pos] <= '9') @@ -2561,7 +2481,7 @@ void xlsx_producer::write_vml_drawings(const relationship &rel, worksheet ws, for (const auto &cell_ref : cells) { - auto comment = ws.get_cell(cell_ref).comment(); + auto comment = ws.cell(cell_ref).comment(); auto shape_id = 1024 * file_index + 1 + comment_index * 2; serializer().start_element(xmlns_v, "shape"); @@ -2632,10 +2552,10 @@ void xlsx_producer::write_vml_drawings(const relationship &rel, worksheet ws, serializer().characters("False"); serializer().end_element(xmlns_x, "AutoFill"); serializer().start_element(xmlns_x, "Row"); - serializer().characters(cell_ref.get_row() - 1); + serializer().characters(cell_ref.row() - 1); serializer().end_element(xmlns_x, "Row"); serializer().start_element(xmlns_x, "Column"); - serializer().characters(cell_ref.get_column_index().index - 1); + serializer().characters(cell_ref.column_index() - 1); serializer().end_element(xmlns_x, "Column"); serializer().end_element(xmlns_x, "ClientData"); @@ -2661,13 +2581,12 @@ void xlsx_producer::write_unknown_relationships() { } -void xlsx_producer::write_thumbnail(const relationship &rel) +void xlsx_producer::write_image(const path &image_path) { end_part(); - const auto &thumbnail = source_.get_thumbnail(); - vector_istreambuf thumbnail_buffer(thumbnail); - archive_->open(rel.get_target().get_path().string()) << &thumbnail_buffer; + vector_istreambuf buffer(source_.d_->images_.at(image_path.string())); + archive_->open(image_path.string()) << &buffer; } xml::serializer &xlsx_producer::serializer() @@ -2677,11 +2596,6 @@ xml::serializer &xlsx_producer::serializer() std::string xlsx_producer::write_bool(bool boolean) const { - if (source_.d_->short_bools_) - { - return boolean ? "1" : "0"; - } - return boolean ? "true" : "false"; } @@ -2698,7 +2612,7 @@ void xlsx_producer::write_relationships(const std::vector &r path rels_path(parent.append("_rels").append(part.filename() + ".rels").string()); begin_part(rels_path); - const auto xmlns = xlnt::constants::get_namespace("relationships"); + const auto xmlns = xlnt::constants::namespace_("relationships"); serializer().start_element(xmlns, "Relationships"); serializer().namespace_decl(xmlns, ""); @@ -2707,11 +2621,11 @@ void xlsx_producer::write_relationships(const std::vector &r { serializer().start_element(xmlns, "Relationship"); - serializer().attribute("Id", relationship.get_id()); - serializer().attribute("Type", relationship.get_type()); - serializer().attribute("Target", relationship.get_target().get_path().string()); + serializer().attribute("Id", relationship.id()); + serializer().attribute("Type", relationship.type()); + serializer().attribute("Target", relationship.target().path().string()); - if (relationship.get_target_mode() == xlnt::target_mode::external) + if (relationship.target_mode() == xlnt::target_mode::external) { serializer().attribute("TargetMode", "External"); } @@ -2725,22 +2639,24 @@ void xlsx_producer::write_relationships(const std::vector &r void xlsx_producer::write_color(const xlnt::color &color) { - switch (color.get_type()) + if (color.is_auto()) + { + serializer().attribute("auto", write_bool(true)); + return; + } + + switch (color.type()) { - case xlnt::color::type::theme: - serializer().attribute("theme", color.get_theme().get_index()); + case xlnt::color_type::theme: + serializer().attribute("theme", color.theme().index()); break; - case xlnt::color::type::indexed: - serializer().attribute("indexed", color.get_indexed().get_index()); + case xlnt::color_type::indexed: + serializer().attribute("indexed", color.indexed().index()); break; - case xlnt::color::type::auto_: - serializer().attribute("auto", color.get_indexed().get_index()); - break; - - case xlnt::color::type::rgb: - serializer().attribute("rgb", color.get_rgb().get_hex_string()); + case xlnt::color_type::rgb: + serializer().attribute("rgb", color.rgb().hex_string()); break; } } diff --git a/source/detail/xlsx_producer.hpp b/source/detail/xlsx_producer.hpp index 3baf517b..f6848b58 100644 --- a/source/detail/xlsx_producer.hpp +++ b/source/detail/xlsx_producer.hpp @@ -74,7 +74,7 @@ private: void write_core_properties(const relationship &rel); void write_extended_properties(const relationship &rel); void write_custom_properties(const relationship &rel); - void write_thumbnail(const relationship &rel); + void write_image(const path &image_path); // SpreadsheetML-Specific Package Parts diff --git a/source/detail/zip.cpp b/source/detail/zip.cpp index 9294121e..47886d22 100644 --- a/source/detail/zip.cpp +++ b/source/detail/zip.cpp @@ -470,32 +470,32 @@ zip_file_ostream::~zip_file_ostream() { } -ZipFileWriter::ZipFileWriter(std::ostream &stream) : target_stream_(stream) +ZipFileWriter::ZipFileWriter(std::ostream &stream) : tarstream_(stream) { - if (!target_stream_) throw std::runtime_error("ZIP: Invalid file handle"); + if (!tarstream_) throw std::runtime_error("ZIP: Invalid file handle"); } ZipFileWriter::~ZipFileWriter() { // Write all file headers - std::ios::streampos final_position = target_stream_.tellp(); + std::ios::streampos final_position = tarstream_.tellp(); for (unsigned int i = 0; i < file_headers_.size(); i++) { - file_headers_[i].Write(target_stream_, true); + file_headers_[i].Write(tarstream_, true); } - std::ios::streampos central_end = target_stream_.tellp(); + std::ios::streampos central_end = tarstream_.tellp(); // Write end of central - write_int(target_stream_, static_cast(0x06054b50)); // end of central - write_int(target_stream_, static_cast(0)); // this disk number - write_int(target_stream_, static_cast(0)); // this disk number - write_int(target_stream_, static_cast(file_headers_.size())); // one entry in center in this disk - write_int(target_stream_, static_cast(file_headers_.size())); // one entry in center - write_int(target_stream_, static_cast(central_end - final_position)); // size of header - write_int(target_stream_, static_cast(final_position)); // offset to header - write_int(target_stream_, static_cast(0)); // zip comment + write_int(tarstream_, static_cast(0x06054b50)); // end of central + write_int(tarstream_, static_cast(0)); // this disk number + write_int(tarstream_, static_cast(0)); // this disk number + write_int(tarstream_, static_cast(file_headers_.size())); // one entry in center in this disk + write_int(tarstream_, static_cast(file_headers_.size())); // one entry in center + write_int(tarstream_, static_cast(central_end - final_position)); // size of header + write_int(tarstream_, static_cast(final_position)); // offset to header + write_int(tarstream_, static_cast(0)); // zip comment } std::ostream &ZipFileWriter::open(const std::string &filename) @@ -503,7 +503,7 @@ std::ostream &ZipFileWriter::open(const std::string &filename) zip_file_header header; header.filename = filename; file_headers_.push_back(header); - auto streambuf = std::make_unique(&file_headers_.back(), target_stream_); + auto streambuf = std::make_unique(&file_headers_.back(), tarstream_); auto stream = new zip_file_ostream(std::move(streambuf)); write_stream_.reset(stream); return *write_stream_; diff --git a/source/detail/zip.hpp b/source/detail/zip.hpp index 232d963b..5653abcd 100644 --- a/source/detail/zip.hpp +++ b/source/detail/zip.hpp @@ -92,7 +92,7 @@ public: void close(); private: std::vector file_headers_; - std::ostream &target_stream_; + std::ostream &tarstream_; std::unique_ptr write_stream_; }; diff --git a/source/packaging/manifest.cpp b/source/packaging/manifest.cpp index 9bd5a4e4..db9ce153 100644 --- a/source/packaging/manifest.cpp +++ b/source/packaging/manifest.cpp @@ -37,7 +37,7 @@ void manifest::clear() relationships_.clear(); } -path manifest::canonicalize(const std::vector &rels) const +path manifest::canonicalize(const std::vector &rels) const { xlnt::path relative; @@ -45,11 +45,11 @@ path manifest::canonicalize(const std::vector &rels) const { if (component == rels.back()) { - relative = relative.append(component.get_target().get_path()); + relative = relative.append(component.target().path()); } else { - relative = relative.append(component.get_target().get_path().parent()); + relative = relative.append(component.target().path().parent()); } } @@ -78,39 +78,39 @@ path manifest::canonicalize(const std::vector &rels) const return result; } -bool manifest::has_relationship(const path &part, relationship::type type) const +bool manifest::has_relationship(const path &part, relationship_type type) const { if (relationships_.find(part) == relationships_.end()) return false; for (const auto &rel : relationships_.at(part)) { - if (rel.second.get_type() == type) return true; + if (rel.second.type() == type) return true; } return false; } -relationship manifest::get_relationship(const path &part, relationship::type type) const +relationship manifest::relationship(const path &part, relationship_type type) const { if (relationships_.find(part) == relationships_.end()) throw key_not_found(); for (const auto &rel : relationships_.at(part)) { - if (rel.second.get_type() == type) return rel.second; + if (rel.second.type() == type) return rel.second; } throw key_not_found(); } -std::vector manifest::get_relationships(const path &part, relationship::type type) const +std::vector manifest::relationships(const path &part, relationship_type type) const { - std::vector matches; + std::vector matches; if (has_relationship(part, type)) { for (const auto &rel : relationships_.at(part)) { - if (rel.second.get_type() == type) + if (rel.second.type() == type) { matches.push_back(rel.second); } @@ -120,18 +120,18 @@ std::vector manifest::get_relationships(const path &part, relation return matches; } -std::string manifest::get_content_type(const path &part) const +std::string manifest::content_type(const path &part) const { auto absolute = part.resolve(path("/")); if (has_override_type(absolute)) { - return get_override_type(absolute); + return override_type(absolute); } if (has_default_type(part.extension())) { - return get_default_type(part.extension()); + return default_type(part.extension()); } throw key_not_found(); @@ -147,7 +147,7 @@ void manifest::unregister_override_type(const path &part) override_content_types_.erase(part); } -std::vector manifest::get_parts_with_overriden_types() const +std::vector manifest::parts_with_overriden_types() const { std::vector overriden; @@ -159,14 +159,14 @@ std::vector manifest::get_parts_with_overriden_types() const return overriden; } -std::vector manifest::get_relationships(const path &part) const +std::vector manifest::relationships(const path &part) const { if (relationships_.find(part) == relationships_.end()) { return {}; } - std::vector relationships; + std::vector relationships; for (const auto &rel : relationships_.at(part)) { @@ -176,7 +176,7 @@ std::vector manifest::get_relationships(const path &part) const return relationships; } -relationship manifest::get_relationship(const path &part, const std::string &rel_id) const +relationship manifest::relationship(const path &part, const std::string &rel_id) const { if (relationships_.find(part) == relationships_.end()) { @@ -185,7 +185,7 @@ relationship manifest::get_relationship(const path &part, const std::string &rel for (const auto &rel : relationships_.at(part)) { - if (rel.second.get_id() == rel_id) + if (rel.second.id() == rel_id) { return rel.second; } @@ -194,7 +194,7 @@ relationship manifest::get_relationship(const path &part, const std::string &rel throw key_not_found(); } -std::vector manifest::get_parts() const +std::vector manifest::parts() const { std::unordered_set parts; @@ -204,9 +204,9 @@ std::vector manifest::get_parts() const for (const auto &rel : part_rels.second) { - if (rel.second.get_target_mode() == target_mode::internal) + if (rel.second.target_mode() == target_mode::internal) { - parts.insert(rel.second.get_target().get_path()); + parts.insert(rel.second.target().path()); } } } @@ -214,20 +214,20 @@ std::vector manifest::get_parts() const return std::vector(parts.begin(), parts.end()); } -std::string manifest::register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode) +std::string manifest::register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode) { - return register_relationship(source, type, target, mode, next_relationship_id(source.get_path())); + return register_relationship(source, type, target, mode, next_relationship_id(source.path())); } -std::string manifest::register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode, const std::string &rel_id) +std::string manifest::register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode, const std::string &rel_id) { - relationships_[source.get_path()][rel_id] = relationship(rel_id, type, source, target, mode); + relationships_[source.path()][rel_id] = xlnt::relationship(rel_id, type, source, target, mode); return rel_id; } void manifest::unregister_relationship(const uri &source, const std::string &rel_id) { - relationships_.at(source.get_path()).erase(rel_id); + relationships_.at(source.path()).erase(rel_id); } bool manifest::has_default_type(const std::string &extension) const @@ -235,7 +235,7 @@ bool manifest::has_default_type(const std::string &extension) const return default_content_types_.find(extension) != default_content_types_.end(); } -std::vector manifest::get_extensions_with_default_types() const +std::vector manifest::extensions_with_default_types() const { std::vector extensions; @@ -247,7 +247,7 @@ std::vector manifest::get_extensions_with_default_types() const return extensions; } -std::string manifest::get_default_type(const std::string &extension) const +std::string manifest::default_type(const std::string &extension) const { if (default_content_types_.find(extension) == default_content_types_.end()) { @@ -287,7 +287,7 @@ bool manifest::has_override_type(const xlnt::path &part) const return override_content_types_.find(part) != override_content_types_.end(); } -std::string manifest::get_override_type(const xlnt::path &part) const +std::string manifest::override_type(const xlnt::path &part) const { if (!has_override_type(part)) { diff --git a/source/packaging/relationship.cpp b/source/packaging/relationship.cpp index 41f296d1..d17f01ea 100644 --- a/source/packaging/relationship.cpp +++ b/source/packaging/relationship.cpp @@ -30,7 +30,7 @@ relationship::relationship() { } -relationship::relationship(const std::string &id, type t, const uri &source, const uri &target, target_mode mode) +relationship::relationship(const std::string &id, relationship_type t, const uri &source, const uri &target, enum target_mode mode) : id_(id), type_(t), source_(source), @@ -39,27 +39,27 @@ relationship::relationship(const std::string &id, type t, const uri &source, con { } -std::string relationship::get_id() const +std::string relationship::id() const { return id_; } -target_mode relationship::get_target_mode() const +target_mode relationship::target_mode() const { return mode_; } -uri relationship::get_source() const +uri relationship::source() const { return source_; } -uri relationship::get_target() const +uri relationship::target() const { return target_; } -relationship::type relationship::get_type() const +relationship_type relationship::type() const { return type_; } diff --git a/source/packaging/uri.cpp b/source/packaging/uri.cpp index 079b95c1..4aaef70c 100644 --- a/source/packaging/uri.cpp +++ b/source/packaging/uri.cpp @@ -15,7 +15,7 @@ std::string uri::to_string() const return path_.string(); } -path uri::get_path() const +path uri::path() const { return path_; } diff --git a/source/styles/color.cpp b/source/styles/color.cpp index ad53e7b5..dd21455d 100644 --- a/source/styles/color.cpp +++ b/source/styles/color.cpp @@ -89,64 +89,73 @@ const color color::darkyellow() } color::color() - : type_(type::auto_), + : type_(color_type::indexed), rgb_(rgb_color(0, 0, 0, 0)), indexed_(0), theme_(0), - tint_(0) + tint_(0), + auto__(false) { } color::color(const rgb_color &rgb) - : type_(type::rgb), - rgb_(rgb), - indexed_(0), - theme_(0), - tint_(0) + : type_(color_type::rgb), + rgb_(rgb), + indexed_(0), + theme_(0), + tint_(0), + auto__(false) { } color::color(const indexed_color &indexed) - : type_(type::indexed), + : type_(color_type::indexed), rgb_(rgb_color(0, 0, 0, 0)), indexed_(indexed), theme_(0), - tint_(0) + tint_(0), + auto__(false) { } color::color(const theme_color &theme) - : type_(type::theme), + : type_(color_type::theme), rgb_(rgb_color(0, 0, 0, 0)), indexed_(0), theme_(theme), - tint_(0) + tint_(0), + auto__(false) { } -color::type color::get_type() const +color_type color::type() const { return type_; } bool color::is_auto() const { - return type_ == type::auto_; + return auto__; } -const indexed_color &color::get_indexed() const +void color::auto_(bool value) { - assert_type(type::indexed); + auto__ = value; +} + +const indexed_color &color::indexed() const +{ + assert_type(color_type::indexed); return indexed_; } -const theme_color &color::get_theme() const +const theme_color &color::theme() const { - assert_type(type::theme); + assert_type(color_type::theme); return theme_; } -std::string rgb_color::get_hex_string() const +std::string rgb_color::hex_string() const { static const char* digits = "0123456789abcdef"; std::string hex_string(8, '0'); @@ -186,28 +195,28 @@ rgb_color::rgb_color(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_ { } -std::size_t indexed_color::get_index() const +std::size_t indexed_color::index() const { return index_; } -std::size_t theme_color::get_index() const +std::size_t theme_color::index() const { return index_; } -const rgb_color &color::get_rgb() const +const rgb_color &color::rgb() const { - assert_type(type::rgb); + assert_type(color_type::rgb); return rgb_; } -void color::set_tint(double tint) +void color::tint(double tint) { tint_ = tint; } -void color::assert_type(type t) const +void color::assert_type(color_type t) const { if (t != type_) { @@ -217,20 +226,21 @@ void color::assert_type(type t) const XLNT_API bool color::operator==(const xlnt::color &other) const { - if (type_ != other.type_ || std::fabs(tint_ - other.tint_) != 0.) + if (type_ != other.type_ + || std::fabs(tint_ - other.tint_) != 0.0 + || auto__ != other.auto__) { return false; } switch(type_) { - case type::auto_: - case type::indexed: - return indexed_.get_index() == other.indexed_.get_index(); - case type::theme: - return theme_.get_index() == other.theme_.get_index(); - case type::rgb: - return rgb_.get_hex_string() == other.rgb_.get_hex_string(); + case color_type::indexed: + return indexed_.index() == other.indexed_.index(); + case color_type::theme: + return theme_.index() == other.theme_.index(); + case color_type::rgb: + return rgb_.hex_string() == other.rgb_.hex_string(); } return false; diff --git a/source/styles/font.cpp b/source/styles/font.cpp index 957b265e..f35d343b 100644 --- a/source/styles/font.cpp +++ b/source/styles/font.cpp @@ -99,6 +99,11 @@ font::underline_style font::underline() const return underline_; } +bool font::has_size() const +{ + return size_.is_set(); +} + font &font::size(std::size_t size) { size_ = size; @@ -107,7 +112,12 @@ font &font::size(std::size_t size) std::size_t font::size() const { - return size_; + return size_.get(); +} + +bool font::has_name() const +{ + return name_.is_set(); } font &font::name(const std::string &name) @@ -115,9 +125,15 @@ font &font::name(const std::string &name) name_ = name; return *this; } + std::string font::name() const { - return name_; + return name_.get(); +} + +bool font::has_color() const +{ + return color_.is_set(); } font &font::color(const xlnt::color &c) @@ -126,31 +142,41 @@ font &font::color(const xlnt::color &c) return *this; } +bool font::has_family() const +{ + return family_.is_set(); +} + font &font::family(std::size_t family) { family_ = family; return *this; } +bool font::has_scheme() const +{ + return scheme_.is_set(); +} + font &font::scheme(const std::string &scheme) { scheme_ = scheme; return *this; } -optional font::color() const +color font::color() const { - return color_; + return color_.get(); } -optional font::family() const +std::size_t font::family() const { - return family_; + return family_.get(); } -optional font::scheme() const +std::string font::scheme() const { - return scheme_; + return scheme_.get(); } XLNT_API bool operator==(const font &left, const font &right) @@ -160,27 +186,27 @@ XLNT_API bool operator==(const font &left, const font &right) return false; } - if (left.color().is_set() != right.color().is_set()) + if (left.has_color() != right.has_color()) { return false; } - if (left.color().is_set()) + if (left.has_color()) { - if (left.color().get() != right.color().get()) + if (left.color() != right.color()) { return false; } } - if (left.family().is_set() != right.family().is_set()) + if (left.has_family() != right.has_family()) { return false; } - if (left.family().is_set()) + if (left.has_family()) { - if (left.family().get() != right.family().get()) + if (left.family() != right.family()) { return false; } @@ -196,14 +222,14 @@ XLNT_API bool operator==(const font &left, const font &right) return false; } - if (left.scheme().is_set() != right.scheme().is_set()) + if (left.has_scheme() != right.has_scheme()) { return false; } - if (left.scheme().is_set()) + if (left.has_scheme()) { - if (left.scheme().get() != right.scheme().get()) + if (left.scheme() != right.scheme()) { return false; } diff --git a/source/styles/format.cpp b/source/styles/format.cpp index 53d80c64..a3463e61 100644 --- a/source/styles/format.cpp +++ b/source/styles/format.cpp @@ -150,7 +150,7 @@ format format::number_format(const xlnt::number_format &new_number_format, bool if (!copy.has_id()) { - copy.set_id(d_->parent->next_custom_number_format_id()); + copy.id(d_->parent->next_custom_number_format_id()); d_->parent->number_formats.push_back(copy); } diff --git a/source/styles/number_format.cpp b/source/styles/number_format.cpp index 9154c867..d8a7e487 100644 --- a/source/styles/number_format.cpp +++ b/source/styles/number_format.cpp @@ -249,12 +249,12 @@ number_format::number_format(std::size_t id) : number_format(from_builtin_id(id) number_format::number_format(const std::string &format_string) : id_set_(false), id_(0) { - set_format_string(format_string); + this->format_string(format_string); } number_format::number_format(const std::string &format_string, std::size_t id) : id_set_(false), id_(0) { - set_format_string(format_string, id); + this->format_string(format_string, id); } number_format number_format::from_builtin_id(std::size_t builtin_id) @@ -268,12 +268,12 @@ number_format number_format::from_builtin_id(std::size_t builtin_id) return number_format(format_string, builtin_id); } -std::string number_format::get_format_string() const +std::string number_format::format_string() const { return format_string_; } -void number_format::set_format_string(const std::string &format_string) +void number_format::format_string(const std::string &format_string) { format_string_ = format_string; id_ = 0; @@ -290,7 +290,7 @@ void number_format::set_format_string(const std::string &format_string) } } -void number_format::set_format_string(const std::string &format_string, std::size_t id) +void number_format::format_string(const std::string &format_string, std::size_t id) { format_string_ = format_string; id_ = id; @@ -299,16 +299,16 @@ void number_format::set_format_string(const std::string &format_string, std::siz bool number_format::has_id() const { - return id_set_; + return id_; } -void number_format::set_id(std::size_t id) +void number_format::id(std::size_t id) { id_ = id; id_set_ = true; } -std::size_t number_format::get_id() const +std::size_t number_format::id() const { if(!id_set_) { @@ -322,7 +322,7 @@ bool number_format::is_date_format() const { detail::number_format_parser p(format_string_); p.parse(); - auto parsed = p.get_result(); + auto parsed = p.result(); bool any_datetime = false; bool any_timedelta = false; diff --git a/source/styles/style.cpp b/source/styles/style.cpp index bf31759c..2946a119 100644 --- a/source/styles/style.cpp +++ b/source/styles/style.cpp @@ -156,16 +156,16 @@ style style::font(const xlnt::font &new_font, bool applied) xlnt::number_format &style::number_format() { - auto target_id = d_->number_format_id.get(); + auto tarid = d_->number_format_id.get(); return *std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(), - [=](const class number_format &nf) { return nf.get_id() == target_id; }); + [=](const class number_format &nf) { return nf.id() == tarid; }); } const xlnt::number_format &style::number_format() const { - auto target_id = d_->number_format_id.get(); + auto tarid = d_->number_format_id.get(); return *std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(), - [=](const class number_format &nf) { return nf.get_id() == target_id; }); + [=](const class number_format &nf) { return nf.id() == tarid; }); } style style::number_format(const xlnt::number_format &new_number_format, bool applied) @@ -174,18 +174,18 @@ style style::number_format(const xlnt::number_format &new_number_format, bool ap if (!copy.has_id()) { - copy.set_id(d_->parent->next_custom_number_format_id()); + copy.id(d_->parent->next_custom_number_format_id()); d_->parent->number_formats.push_back(copy); } else if (std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(), - [©](const class number_format &nf) { return nf.get_id() == copy.get_id(); }) + [©](const class number_format &nf) { return nf.id() == copy.id(); }) == d_->parent->number_formats.end()) { d_->parent->number_formats.push_back(copy); } - d_->number_format_id = copy.get_id(); + d_->number_format_id = copy.id(); d_->number_format_applied = applied; return style(d_); diff --git a/source/styles/tests/test_color.hpp b/source/styles/tests/test_color.hpp index de7c2614..fe034694 100644 --- a/source/styles/tests/test_color.hpp +++ b/source/styles/tests/test_color.hpp @@ -26,28 +26,22 @@ public: for (auto pair : known_colors) { - TS_ASSERT_EQUALS(pair.first.get_rgb().get_hex_string(), pair.second); + TS_ASSERT_EQUALS(pair.first.rgb().hex_string(), pair.second); } } void test_non_rgb_colors() { - xlnt::color auto_; - TS_ASSERT(auto_.is_auto()); - TS_ASSERT_THROWS(auto_.get_theme(), xlnt::invalid_attribute); - TS_ASSERT_THROWS(auto_.get_indexed(), xlnt::invalid_attribute); - TS_ASSERT_THROWS(auto_.get_rgb(), xlnt::invalid_attribute); - xlnt::color indexed = xlnt::indexed_color(1); TS_ASSERT(!indexed.is_auto()); - TS_ASSERT_EQUALS(indexed.get_indexed().get_index(), 1); - TS_ASSERT_THROWS(indexed.get_theme(), xlnt::invalid_attribute); - TS_ASSERT_THROWS(indexed.get_rgb(), xlnt::invalid_attribute); + TS_ASSERT_EQUALS(indexed.indexed().index(), 1); + TS_ASSERT_THROWS(indexed.theme(), xlnt::invalid_attribute); + TS_ASSERT_THROWS(indexed.rgb(), xlnt::invalid_attribute); xlnt::color theme = xlnt::theme_color(3); TS_ASSERT(!theme.is_auto()); - TS_ASSERT_EQUALS(theme.get_theme().get_index(), 3); - TS_ASSERT_THROWS(theme.get_indexed(), xlnt::invalid_attribute); - TS_ASSERT_THROWS(theme.get_rgb(), xlnt::invalid_attribute); + TS_ASSERT_EQUALS(theme.theme().index(), 3); + TS_ASSERT_THROWS(theme.indexed(), xlnt::invalid_attribute); + TS_ASSERT_THROWS(theme.rgb(), xlnt::invalid_attribute); } }; diff --git a/source/styles/tests/test_fill.hpp b/source/styles/tests/test_fill.hpp index 729c61cc..63d110da 100644 --- a/source/styles/tests/test_fill.hpp +++ b/source/styles/tests/test_fill.hpp @@ -32,11 +32,11 @@ public: fill = fill.pattern_fill().foreground(xlnt::color::black()); TS_ASSERT(fill.pattern_fill().foreground()); - TS_ASSERT_EQUALS((*fill.pattern_fill().foreground()).get_rgb().get_hex_string(), xlnt::color::black().get_rgb().get_hex_string()); + TS_ASSERT_EQUALS((*fill.pattern_fill().foreground()).rgb().hex_string(), xlnt::color::black().rgb().hex_string()); fill = fill.pattern_fill().background(xlnt::color::green()); TS_ASSERT(fill.pattern_fill().background()); - TS_ASSERT_EQUALS((*fill.pattern_fill().background()).get_rgb().get_hex_string(), xlnt::color::green().get_rgb().get_hex_string()); + TS_ASSERT_EQUALS((*fill.pattern_fill().background()).rgb().hex_string(), xlnt::color::green().rgb().hex_string()); const auto &const_fill = fill; TS_ASSERT(const_fill.pattern_fill().foreground()); @@ -57,18 +57,18 @@ public: void test_two_fills() { xlnt::workbook wb; - auto ws1 = wb.get_active_sheet(); + auto ws1 = wb.active_sheet(); - auto cell1 = ws1.get_cell("A10"); - auto cell2 = ws1.get_cell("A11"); + auto cell1 = ws1.cell("A10"); + auto cell2 = ws1.cell("A11"); - cell1.set_fill(xlnt::fill::solid(xlnt::color::yellow())); - cell1.set_value("Fill Yellow"); + cell1.fill(xlnt::fill::solid(xlnt::color::yellow())); + cell1.value("Fill Yellow"); - cell2.set_fill(xlnt::fill::solid(xlnt::color::green())); - cell2.set_value(xlnt::date(2010, 7, 13)); + cell2.fill(xlnt::fill::solid(xlnt::color::green())); + cell2.value(xlnt::date(2010, 7, 13)); - TS_ASSERT_EQUALS(cell1.get_fill(), xlnt::fill::solid(xlnt::color::yellow())); - TS_ASSERT_EQUALS(cell2.get_fill(), xlnt::fill::solid(xlnt::color::green())); + TS_ASSERT_EQUALS(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow())); + TS_ASSERT_EQUALS(cell2.fill(), xlnt::fill::solid(xlnt::color::green())); } }; diff --git a/source/styles/tests/test_number_format.hpp b/source/styles/tests/test_number_format.hpp index c5263edb..e0523275 100644 --- a/source/styles/tests/test_number_format.hpp +++ b/source/styles/tests/test_number_format.hpp @@ -11,33 +11,33 @@ public: void test_basic() { xlnt::number_format no_id("#\\x\\y\\z"); - TS_ASSERT_THROWS(no_id.get_id(), std::runtime_error); + TS_ASSERT_THROWS(no_id.id(), std::runtime_error); xlnt::number_format id("General", 200); - TS_ASSERT_EQUALS(id.get_id(), 200); - TS_ASSERT_EQUALS(id.get_format_string(), "General"); + TS_ASSERT_EQUALS(id.id(), 200); + TS_ASSERT_EQUALS(id.format_string(), "General"); xlnt::number_format general(0); TS_ASSERT_EQUALS(general, xlnt::number_format::general()); - TS_ASSERT_EQUALS(general.get_id(), 0); - TS_ASSERT_EQUALS(general.get_format_string(), "General"); + TS_ASSERT_EQUALS(general.id(), 0); + TS_ASSERT_EQUALS(general.format_string(), "General"); } void test_simple_format() { xlnt::number_format nf; - nf.set_format_string("\"positive\"General;\"negative\"General"); + nf.format_string("\"positive\"General;\"negative\"General"); auto formatted = nf.format(3.14, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "positive3.14"); formatted = nf.format(-3.14, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "negative3.14"); - nf.set_format_string("\"any\"General"); + nf.format_string("\"any\"General"); formatted = nf.format(-3.14, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "-any3.14"); - nf.set_format_string("\"positive\"General;\"negative\"General;\"zero\"General"); + nf.format_string("\"positive\"General;\"negative\"General;\"zero\"General"); formatted = nf.format(3.14, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "positive3.14"); formatted = nf.format(-3.14, xlnt::calendar::windows_1900); @@ -63,7 +63,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("m"); + nf.format_string("m"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); @@ -75,7 +75,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("mmm"); + nf.format_string("mmm"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "Jun"); @@ -87,7 +87,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("mmmm"); + nf.format_string("mmmm"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "June"); @@ -99,7 +99,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("d"); + nf.format_string("d"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "8"); @@ -111,7 +111,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("dd"); + nf.format_string("dd"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "08"); @@ -123,7 +123,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("yyyy"); + nf.format_string("yyyy"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "2016"); @@ -135,7 +135,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("dddd"); + nf.format_string("dddd"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "Sunday"); @@ -147,7 +147,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("ddd"); + nf.format_string("ddd"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "Sun"); @@ -159,7 +159,7 @@ public: auto date_number = date.to_number(xlnt::calendar::windows_1900); xlnt::number_format nf; - nf.set_format_string("mmmmm"); + nf.format_string("mmmmm"); auto formatted = nf.format(date_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "J"); @@ -248,7 +248,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("hh AM/PM"); + nf.format_string("hh AM/PM"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "08 PM"); @@ -277,7 +277,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("hh"); + nf.format_string("hh"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20"); @@ -289,7 +289,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("h:m"); + nf.format_string("h:m"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20:5"); @@ -301,7 +301,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("h:mm"); + nf.format_string("h:mm"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20:05"); @@ -313,7 +313,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("h:m:s"); + nf.format_string("h:m:s"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20:15:1"); @@ -325,7 +325,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("h:m:ss"); + nf.format_string("h:m:ss"); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20:15:01"); @@ -337,7 +337,7 @@ public: auto time_number = time.to_number(); xlnt::number_format nf; - nf.set_format_string("h:m:ss "); + nf.format_string("h:m:ss "); auto formatted = nf.format(time_number, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "20:15:01 "); @@ -346,7 +346,7 @@ public: void test_text_section_string() { xlnt::number_format nf; - nf.set_format_string("General;General;General;[Green]\"a\"@\"b\""); + nf.format_string("General;General;General;[Green]\"a\"@\"b\""); auto formatted = nf.format("text"); @@ -356,7 +356,7 @@ public: void test_text_section_no_string() { xlnt::number_format nf; - nf.set_format_string("General;General;General;[Green]m\"ab\""); + nf.format_string("General;General;General;[Green]m\"ab\""); auto formatted = nf.format("text"); @@ -366,7 +366,7 @@ public: void test_text_section_no_text() { xlnt::number_format nf; - nf.set_format_string("General;General;General;[Green]m"); + nf.format_string("General;General;General;[Green]m"); auto formatted = nf.format("text"); @@ -377,7 +377,7 @@ public: { xlnt::number_format nf; - nf.set_format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General"); + nf.format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6first"); formatted = nf.format(4, xlnt::calendar::windows_1900); @@ -389,7 +389,7 @@ public: formatted = nf.format(2, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "third2"); - nf.set_format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General"); + nf.format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General"); formatted = nf.format(5, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "first5"); formatted = nf.format(6, xlnt::calendar::windows_1900); @@ -401,15 +401,15 @@ public: formatted = nf.format(2, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "third2"); - nf.set_format_string("[>=5]\"first\"General"); + nf.format_string("[>=5]\"first\"General"); formatted = nf.format(4, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "###########"); - nf.set_format_string("[>=5]\"first\"General;[>=4]\"second\"General"); + nf.format_string("[>=5]\"first\"General;[>=4]\"second\"General"); formatted = nf.format(3, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "###########"); - nf.set_format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General"); + nf.format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General"); formatted = nf.format(0, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "first0"); formatted = nf.format(1, xlnt::calendar::windows_1900); @@ -419,7 +419,7 @@ public: formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "third6"); - nf.set_format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General"); + nf.format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General"); formatted = nf.format(-1000, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "-first1000"); formatted = nf.format(0, xlnt::calendar::windows_1900); @@ -435,7 +435,7 @@ public: formatted = nf.format(1000, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "third1000"); - nf.set_format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General"); + nf.format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General"); formatted = nf.format(1, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "first1"); formatted = nf.format(2, xlnt::calendar::windows_1900); @@ -445,7 +445,7 @@ public: formatted = nf.format(0, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "third0"); - nf.set_format_string("[<>1]\"first\"General;[<>2]\"second\"General"); + nf.format_string("[<>1]\"first\"General;[<>2]\"second\"General"); formatted = nf.format(2, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "first2"); formatted = nf.format(1, xlnt::calendar::windows_1900); @@ -455,7 +455,7 @@ public: void test_space() { xlnt::number_format nf; - nf.set_format_string("_(General_)"); + nf.format_string("_(General_)"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, " 6 "); } @@ -463,15 +463,15 @@ public: void test_fill() { xlnt::number_format nf; - nf.set_format_string("*-General"); + nf.format_string("*-General"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "----------6"); - nf.set_format_string("General*-"); + nf.format_string("General*-"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6----------"); - nf.set_format_string("\\a*-\\b"); + nf.format_string("\\a*-\\b"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "a---------b"); } @@ -479,11 +479,11 @@ public: void test_placeholders_zero() { xlnt::number_format nf; - nf.set_format_string("00"); + nf.format_string("00"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "06"); - nf.set_format_string("00"); + nf.format_string("00"); formatted = nf.format(63, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "63"); } @@ -491,23 +491,23 @@ public: void test_placeholders_space() { xlnt::number_format nf; - nf.set_format_string("?0"); + nf.format_string("?0"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, " 6"); - nf.set_format_string("?0"); + nf.format_string("?0"); formatted = nf.format(63, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "63"); - nf.set_format_string("?0"); + nf.format_string("?0"); formatted = nf.format(637, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "637"); - nf.set_format_string("0.?"); + nf.format_string("0.?"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6. "); - nf.set_format_string("0.0?"); + nf.format_string("0.0?"); formatted = nf.format(6.3, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6.3 "); formatted = nf.format(6.34, xlnt::calendar::windows_1900); @@ -517,7 +517,7 @@ public: void test_scientific() { xlnt::number_format nf; - nf.set_format_string("0.0E-0"); + nf.format_string("0.0E-0"); auto formatted = nf.format(6.1, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6.1E0"); } @@ -526,11 +526,11 @@ public: { xlnt::number_format nf; - nf.set_format_string("[$€-407]#,##0.00"); + nf.format_string("[$€-407]#,##0.00"); auto formatted = nf.format(-45000.1, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "-€45,000.10"); - nf.set_format_string("[$$-1009]#,##0.00"); + nf.format_string("[$$-1009]#,##0.00"); formatted = nf.format(-45000.1, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "-$45,000.10"); } @@ -539,16 +539,16 @@ public: { xlnt::number_format nf; - nf.set_format_string("[$-]#,##0.00"); + nf.format_string("[$-]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[$-G]#,##0.00"); + nf.format_string("[$-G]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[$-4002]#,##0.00"); + nf.format_string("[$-4002]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[-4001]#,##0.00"); + nf.format_string("[-4001]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); } @@ -556,13 +556,13 @@ public: { xlnt::number_format nf; - nf.set_format_string("[Red][Green]#,##0.00"); + nf.format_string("[Red][Green]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[$-403][$-4001]#,##0.00"); + nf.format_string("[$-403][$-4001]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[>3][>4]#,##0.00"); + nf.format_string("[>3][>4]#,##0.00"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); } @@ -570,7 +570,7 @@ public: { xlnt::number_format nf; - nf.set_format_string("\"\\\"\"General"); + nf.format_string("\"\\\"\"General"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "\"6"); } @@ -579,7 +579,7 @@ public: { xlnt::number_format nf; - nf.set_format_string("#,"); + nf.format_string("#,"); auto formatted = nf.format(61234, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "61"); } @@ -588,43 +588,43 @@ public: { xlnt::number_format nf; - nf.set_format_string("[Black]#"); + nf.format_string("[Black]#"); auto formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Black]#"); + nf.format_string("[Black]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Blue]#"); + nf.format_string("[Blue]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Green]#"); + nf.format_string("[Green]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Red]#"); + nf.format_string("[Red]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Cyan]#"); + nf.format_string("[Cyan]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Magenta]#"); + nf.format_string("[Magenta]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Yellow]#"); + nf.format_string("[Yellow]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[White]#"); + nf.format_string("[White]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); - nf.set_format_string("[Color15]#"); + nf.format_string("[Color15]#"); formatted = nf.format(6, xlnt::calendar::windows_1900); TS_ASSERT_EQUALS(formatted, "6"); } @@ -633,31 +633,31 @@ public: { xlnt::number_format nf; - nf.set_format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General"); + nf.format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General"); + nf.format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("["); + nf.format_string("["); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[]"); + nf.format_string("[]"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[Redd]"); + nf.format_string("[Redd]"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("[$1]#"); + nf.format_string("[$1]#"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("Gee"); + nf.format_string("Gee"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("!"); + nf.format_string("!"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); - nf.set_format_string("A/"); + nf.format_string("A/"); TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error); } diff --git a/source/utils/datetime.cpp b/source/utils/datetime.cpp index ad4fc347..40e92df8 100644 --- a/source/utils/datetime.cpp +++ b/source/utils/datetime.cpp @@ -27,6 +27,20 @@ #include #include +namespace { + +std::string fill(const std::string &string, std::size_t length = 2) +{ + if (string.size() >= length) + { + return string; + } + + return std::string(length - string.size(), '0') + string; +} + +} // namespace + namespace xlnt { datetime datetime::from_number(long double raw_time, calendar base_date) @@ -92,4 +106,33 @@ int datetime::weekday() const return date(year, month, day).weekday(); } +datetime datetime::from_iso_string(const std::string &string) +{ + xlnt::datetime result(1900, 1, 1); + + auto separator_index = string.find('-'); + result.year = std::stoi(string.substr(0, separator_index)); + result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1))); + separator_index = string.find('-', separator_index + 1); + result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1))); + separator_index = string.find('T', separator_index + 1); + result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); + separator_index = string.find(':', separator_index + 1); + result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); + separator_index = string.find(':', separator_index + 1); + result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1))); + + return result; +} + +std::string datetime::to_iso_string() const +{ + return std::to_string(year) + "-" + + fill(std::to_string(month)) + "-" + + fill(std::to_string(day)) + "T" + + fill(std::to_string(hour)) + ":" + + fill(std::to_string(minute)) + ":" + + fill(std::to_string(second)) + "Z"; +} + } // namespace xlnt diff --git a/source/utils/exceptions.cpp b/source/utils/exceptions.cpp index 949af833..d5228ee1 100644 --- a/source/utils/exceptions.cpp +++ b/source/utils/exceptions.cpp @@ -29,14 +29,14 @@ namespace xlnt { exception::exception(const std::string &message) : std::runtime_error("xlnt::error : " + message) { - set_message(message); + this->message(message); } exception::~exception() { } -void exception::set_message(const std::string &message) +void exception::message(const std::string &message) { message_ = message; } diff --git a/source/utils/path.cpp b/source/utils/path.cpp index 0a6a36c7..467da0fb 100644 --- a/source/utils/path.cpp +++ b/source/utils/path.cpp @@ -293,6 +293,29 @@ char path::guess_separator() const return internal_.find('\\') != std::string::npos ? '\\' : '/'; } +path path::relative_to(const path &base_path) const +{ + if (is_relative()) return *this; + + auto base_split = base_path.split(); + auto this_split = split(); + auto index = std::size_t(0); + + while (index < base_split.size() && index < this_split.size() && base_split[index] == this_split[index]) + { + index++; + } + + auto result = path(); + + for (auto i = index; i < this_split.size(); i++) + { + result = result.append(this_split[i]); + } + + return result; +} + bool operator==(const path &left, const path &right) { return left.internal_ == right.internal_; diff --git a/source/workbook/const_worksheet_iterator.cpp b/source/workbook/const_worksheet_iterator.cpp index ae767e0d..afb9bc44 100644 --- a/source/workbook/const_worksheet_iterator.cpp +++ b/source/workbook/const_worksheet_iterator.cpp @@ -37,7 +37,7 @@ const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterato const worksheet const_worksheet_iterator::operator*() { - return wb_.get_sheet_by_index(index_); + return wb_.sheet_by_index(index_); } const_worksheet_iterator &const_worksheet_iterator::operator++() diff --git a/source/workbook/named_range.cpp b/source/workbook/named_range.cpp index c2dcb536..39ee57d1 100644 --- a/source/workbook/named_range.cpp +++ b/source/workbook/named_range.cpp @@ -58,12 +58,12 @@ std::vector split_string(const std::string &string, char delim) namespace xlnt { -std::string named_range::get_name() const +std::string named_range::name() const { return name_; } -const std::vector &named_range::get_targets() const +const std::vector &named_range::targets() const { return targets_; } diff --git a/source/workbook/tests/test_consume_xlsx.hpp b/source/workbook/tests/test_consume_xlsx.hpp index 57413f65..3964fe69 100644 --- a/source/workbook/tests/test_consume_xlsx.hpp +++ b/source/workbook/tests/test_consume_xlsx.hpp @@ -56,14 +56,14 @@ public: wb.load("data/18_basic_comments.xlsx"); auto sheet1 = wb[0]; - TS_ASSERT_EQUALS(sheet1.get_cell("A1").get_value(), "Sheet1!A1"); - TS_ASSERT_EQUALS(sheet1.get_cell("A1").comment().plain_text(), "Sheet1 comment"); - TS_ASSERT_EQUALS(sheet1.get_cell("A1").comment().author(), "Microsoft Office User"); + TS_ASSERT_EQUALS(sheet1.cell("A1").value(), "Sheet1!A1"); + TS_ASSERT_EQUALS(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment"); + TS_ASSERT_EQUALS(sheet1.cell("A1").comment().author(), "Microsoft Office User"); auto sheet2 = wb[1]; - TS_ASSERT_EQUALS(sheet2.get_cell("A1").get_value(), "Sheet2!A1"); - TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().plain_text(), "Sheet2 comment"); - TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().author(), "Microsoft Office User"); + TS_ASSERT_EQUALS(sheet2.cell("A1").value(), "Sheet2!A1"); + TS_ASSERT_EQUALS(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment"); + TS_ASSERT_EQUALS(sheet2.cell("A1").comment().author(), "Microsoft Office User"); } void test_read_unicode_filename() @@ -71,12 +71,12 @@ public: #ifdef _MSC_VER xlnt::workbook wb; wb.load(L"data\\19_unicode_Λ.xlsx"); - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("A1").get_value(), "unicode!"); + TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value(), "unicode!"); #endif #ifndef __MINGW32__ xlnt::workbook wb2; wb2.load(u8"data/19_unicode_Λ.xlsx"); - TS_ASSERT_EQUALS(wb2.get_active_sheet().get_cell("A1").get_value(), "unicode!"); + TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value(), "unicode!"); #endif } @@ -84,8 +84,8 @@ public: { xlnt::workbook wb; wb.load("data/20_with_hyperlink.xlsx"); - TS_ASSERT(wb.get_active_sheet().get_cell("A1").has_hyperlink()); - TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("A1").get_hyperlink(), + TS_ASSERT(wb.active_sheet().cell("A1").has_hyperlink()); + TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").hyperlink(), "https://fr.wikipedia.org/wiki/Ille-et-Vilaine"); } }; diff --git a/source/workbook/tests/test_produce_xlsx.hpp b/source/workbook/tests/test_produce_xlsx.hpp index 6e662f53..f3a8173a 100644 --- a/source/workbook/tests/test_produce_xlsx.hpp +++ b/source/workbook/tests/test_produce_xlsx.hpp @@ -50,75 +50,75 @@ public: void test_produce_simple_excel() { xlnt::workbook wb = xlnt::workbook::empty_excel(); - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto bold_font = xlnt::font().bold(true); - ws.get_cell("A1").set_value("Type"); - ws.get_cell("A1").set_font(bold_font); + ws.cell("A1").value("Type"); + ws.cell("A1").font(bold_font); - ws.get_cell("B1").set_value("Value"); - ws.get_cell("B1").set_font(bold_font); + ws.cell("B1").value("Value"); + ws.cell("B1").font(bold_font); - ws.get_cell("A2").set_value("null"); - ws.get_cell("B2").set_value(nullptr); + ws.cell("A2").value("null"); + ws.cell("B2").value(nullptr); - ws.get_cell("A3").set_value("bool (true)"); - ws.get_cell("B3").set_value(true); + ws.cell("A3").value("bool (true)"); + ws.cell("B3").value(true); - ws.get_cell("A4").set_value("bool (false)"); - ws.get_cell("B4").set_value(false); + ws.cell("A4").value("bool (false)"); + ws.cell("B4").value(false); - ws.get_cell("A5").set_value("number (std::int8_t)"); - ws.get_cell("B5").set_value(std::numeric_limits::max()); + ws.cell("A5").value("number (std::int8_t)"); + ws.cell("B5").value(std::numeric_limits::max()); - ws.get_cell("A6").set_value("number (std::uint8_t)"); - ws.get_cell("B6").set_value(std::numeric_limits::max()); + ws.cell("A6").value("number (std::uint8_t)"); + ws.cell("B6").value(std::numeric_limits::max()); - ws.get_cell("A7").set_value("number (std::uint16_t)"); - ws.get_cell("B7").set_value(std::numeric_limits::max()); + ws.cell("A7").value("number (std::uint16_t)"); + ws.cell("B7").value(std::numeric_limits::max()); - ws.get_cell("A8").set_value("number (std::uint16_t)"); - ws.get_cell("B8").set_value(std::numeric_limits::max()); + ws.cell("A8").value("number (std::uint16_t)"); + ws.cell("B8").value(std::numeric_limits::max()); - ws.get_cell("A9").set_value("number (std::uint32_t)"); - ws.get_cell("B9").set_value(std::numeric_limits::max()); + ws.cell("A9").value("number (std::uint32_t)"); + ws.cell("B9").value(std::numeric_limits::max()); - ws.get_cell("A10").set_value("number (std::uint32_t)"); - ws.get_cell("B10").set_value(std::numeric_limits::max()); + ws.cell("A10").value("number (std::uint32_t)"); + ws.cell("B10").value(std::numeric_limits::max()); - ws.get_cell("A11").set_value("number (std::uint64_t)"); - ws.get_cell("B11").set_value(std::numeric_limits::max()); + ws.cell("A11").value("number (std::uint64_t)"); + ws.cell("B11").value(std::numeric_limits::max()); - ws.get_cell("A12").set_value("number (std::uint64_t)"); - ws.get_cell("B12").set_value(std::numeric_limits::max()); + ws.cell("A12").value("number (std::uint64_t)"); + ws.cell("B12").value(std::numeric_limits::max()); - ws.get_cell("A13").set_value("number (float)"); - ws.get_cell("B13").set_value(std::numeric_limits::max()); + ws.cell("A13").value("number (float)"); + ws.cell("B13").value(std::numeric_limits::max()); - ws.get_cell("A14").set_value("number (double)"); - ws.get_cell("B14").set_value(std::numeric_limits::max()); + ws.cell("A14").value("number (double)"); + ws.cell("B14").value(std::numeric_limits::max()); - ws.get_cell("A15").set_value("number (long double)"); - ws.get_cell("B15").set_value(std::numeric_limits::max()); + ws.cell("A15").value("number (long double)"); + ws.cell("B15").value(std::numeric_limits::max()); - ws.get_cell("A16").set_value("text (char *)"); - ws.get_cell("B16").set_value("string"); + ws.cell("A16").value("text (char *)"); + ws.cell("B16").value("string"); - ws.get_cell("A17").set_value("text (std::string)"); - ws.get_cell("B17").set_value(std::string("string")); + ws.cell("A17").value("text (std::string)"); + ws.cell("B17").value(std::string("string")); - ws.get_cell("A18").set_value("date"); - ws.get_cell("B18").set_value(xlnt::date(2016, 2, 3)); + ws.cell("A18").value("date"); + ws.cell("B18").value(xlnt::date(2016, 2, 3)); - ws.get_cell("A19").set_value("time"); - ws.get_cell("B19").set_value(xlnt::time(1, 2, 3, 4)); + ws.cell("A19").value("time"); + ws.cell("B19").value(xlnt::time(1, 2, 3, 4)); - ws.get_cell("A20").set_value("datetime"); - ws.get_cell("B20").set_value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4)); + ws.cell("A20").value("datetime"); + ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4)); - ws.get_cell("A21").set_value("timedelta"); - ws.get_cell("B21").set_value(xlnt::timedelta(1, 2, 3, 4, 5)); + ws.cell("A21").value("timedelta"); + ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5)); ws.freeze_panes("B2"); @@ -131,14 +131,14 @@ public: { xlnt::workbook workbook; - TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 1); + TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1); auto sheet = workbook.create_sheet(); - sheet.set_title("XXX1"); - TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 2); + sheet.title("XXX1"); + TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 2); - workbook.remove_sheet(workbook.get_sheet_by_title("XXX1")); - TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 1); + workbook.remove_sheet(workbook.sheet_by_title("XXX1")); + TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1); std::vector temp_buffer; TS_ASSERT_THROWS_NOTHING(workbook.save(temp_buffer)); @@ -151,37 +151,37 @@ public: xlnt::formatted_text comment_text; xlnt::text_run formatted_run;; - formatted_run.set_bold(true); - formatted_run.set_size(10); - formatted_run.set_color(xlnt::indexed_color(81)); - formatted_run.set_font("Calibri"); + formatted_run.bold(true); + formatted_run.size(10); + formatted_run.color(xlnt::indexed_color(81)); + formatted_run.font("Calibri"); - auto sheet1 = wb.get_active_sheet(); + auto sheet1 = wb.active_sheet(); - sheet1.get_cell("A1").set_value("Sheet1!A1"); - formatted_run.set_string("Sheet1 comment"); + sheet1.cell("A1").value("Sheet1!A1"); + formatted_run.string("Sheet1 comment"); comment_text.add_run(formatted_run); - sheet1.get_cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User")); - sheet1.get_cell("A1").comment("Sheet1 comment"); + sheet1.cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User")); + sheet1.cell("A1").comment("Sheet1 comment"); - sheet1.get_cell("A2").set_value("Sheet1!A2"); - formatted_run.set_string("Sheet1 comment2"); + sheet1.cell("A2").value("Sheet1!A2"); + formatted_run.string("Sheet1 comment2"); comment_text.clear(); comment_text.add_run(formatted_run); - sheet1.get_cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User")); + sheet1.cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User")); auto sheet2 = wb.create_sheet(); - sheet2.get_cell("A1").set_value("Sheet2!A1"); - formatted_run.set_string("Sheet2 comment"); + sheet2.cell("A1").value("Sheet2!A1"); + formatted_run.string("Sheet2 comment"); comment_text.clear(); comment_text.add_run(formatted_run); - sheet2.get_cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User")); + sheet2.cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User")); - sheet2.get_cell("A2").set_value("Sheet2!A2"); - formatted_run.set_string("Sheet2 comment2"); + sheet2.cell("A2").value("Sheet2!A2"); + formatted_run.string("Sheet2 comment2"); comment_text.clear(); comment_text.add_run(formatted_run); - sheet2.get_cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User")); + sheet2.cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User")); // TS_ASSERT(workbook_matches_file(wb, xlnt::path("data/18_basic_comments.xlsx"))); } diff --git a/source/workbook/tests/test_round_trip.hpp b/source/workbook/tests/test_round_trip.hpp index 13f76150..6dc7cb27 100644 --- a/source/workbook/tests/test_round_trip.hpp +++ b/source/workbook/tests/test_round_trip.hpp @@ -52,6 +52,7 @@ public: std::vector buffer; original_workbook.save(buffer); + original_workbook.save("a.xlsx"); return xml_helper::xlsx_archives_match(original_data, buffer); } @@ -76,7 +77,6 @@ public: void test_round_trip_empty_numbers_wrw() { - TS_SKIP(""); xlnt::workbook wb = xlnt::workbook::empty_numbers(); TS_ASSERT(round_trip_matches_wrw(wb)); } @@ -101,8 +101,7 @@ public: void test_round_trip_empty_numbers_rw() { - TS_SKIP(""); - auto path = path_helper::get_data_directory("10_default-numbers.xlsx"); + auto path = path_helper::get_data_directory("11_default-numbers.xlsx"); TS_ASSERT(round_trip_matches_rw(path)); } diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index ee57aefa..3aa22199 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -12,10 +12,10 @@ class test_workbook : public CxxTest::TestSuite { public: - void test_get_active_sheet() + void test_active_sheet() { xlnt::workbook wb; - TS_ASSERT_EQUALS(wb.get_active_sheet(), wb[0]); + TS_ASSERT_EQUALS(wb.active_sheet(), wb[0]); } void test_create_sheet() @@ -30,42 +30,42 @@ public: { xlnt::workbook wb; auto new_sheet = wb.create_sheet(); - new_sheet.get_cell("A6").set_value(1.498); + new_sheet.cell("A6").value(1.498); wb.copy_sheet(new_sheet); TS_ASSERT(wb[1].compare(wb[2], false)); - wb.create_sheet().get_cell("A6").set_value(1.497); + wb.create_sheet().cell("A6").value(1.497); TS_ASSERT(!wb[1].compare(wb[3], false)); } void test_add_sheet_from_other_workbook() { xlnt::workbook wb1, wb2; - auto new_sheet = wb1.get_active_sheet(); + auto new_sheet = wb1.active_sheet(); TS_ASSERT_THROWS(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter); - TS_ASSERT_THROWS(wb2.get_index(new_sheet), std::runtime_error); + TS_ASSERT_THROWS(wb2.index(new_sheet), std::runtime_error); } void test_add_sheet_at_index() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.get_cell("B3").set_value(2); - ws.set_title("Active"); + auto ws = wb.active_sheet(); + ws.cell("B3").value(2); + ws.title("Active"); wb.copy_sheet(ws, 0); - TS_ASSERT_EQUALS(wb.get_sheet_titles().at(0), "Sheet1"); - TS_ASSERT_EQUALS(wb.get_sheet_by_index(0).get_cell("B3").get_value(), 2); - TS_ASSERT_EQUALS(wb.get_sheet_titles().at(1), "Active"); - TS_ASSERT_EQUALS(wb.get_sheet_by_index(1).get_cell("B3").get_value(), 2); + TS_ASSERT_EQUALS(wb.sheet_titles().at(0), "Sheet1"); + TS_ASSERT_EQUALS(wb.sheet_by_index(0).cell("B3").value(), 2); + TS_ASSERT_EQUALS(wb.sheet_titles().at(1), "Active"); + TS_ASSERT_EQUALS(wb.sheet_by_index(1).cell("B3").value(), 2); } void test_remove_sheet() { xlnt::workbook wb, wb2; auto new_sheet = wb.create_sheet(0); - new_sheet.set_title("removed"); + new_sheet.title("removed"); wb.remove_sheet(new_sheet); TS_ASSERT(!wb.contains("removed")); - TS_ASSERT_THROWS(wb.remove_sheet(wb2.get_active_sheet()), std::runtime_error); + TS_ASSERT_THROWS(wb.remove_sheet(wb2.active_sheet()), std::runtime_error); } void test_get_sheet_by_title() @@ -73,12 +73,12 @@ public: xlnt::workbook wb; auto new_sheet = wb.create_sheet(); std::string title = "my sheet"; - new_sheet.set_title(title); - auto found_sheet = wb.get_sheet_by_title(title); + new_sheet.title(title); + auto found_sheet = wb.sheet_by_title(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); - TS_ASSERT_THROWS(wb.get_sheet_by_title("error"), xlnt::key_not_found); + TS_ASSERT_THROWS(wb.sheet_by_title("error"), xlnt::key_not_found); const auto &wb_const = wb; - TS_ASSERT_THROWS(wb_const.get_sheet_by_title("error"), xlnt::key_not_found); + TS_ASSERT_THROWS(wb_const.sheet_by_title("error"), xlnt::key_not_found); } void test_get_sheet_by_title_const() @@ -86,9 +86,9 @@ public: xlnt::workbook wb; auto new_sheet = wb.create_sheet(); std::string title = "my sheet"; - new_sheet.set_title(title); + new_sheet.title(title); const xlnt::workbook& wbconst = wb; - auto found_sheet = wbconst.get_sheet_by_title(title); + auto found_sheet = wbconst.sheet_by_title(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); } @@ -114,31 +114,31 @@ public: for(auto ws : wb) { - TS_ASSERT_EQUALS(ws.get_title(), "Sheet1"); + TS_ASSERT_EQUALS(ws.title(), "Sheet1"); } } void test_get_index() { xlnt::workbook wb; - wb.create_sheet().set_title("1"); - wb.create_sheet().set_title("2"); + wb.create_sheet().title("1"); + wb.create_sheet().title("2"); - auto sheet_index = wb.get_index(wb.get_sheet_by_title("1")); + auto sheet_index = wb.index(wb.sheet_by_title("1")); TS_ASSERT_EQUALS(sheet_index, 1); - sheet_index = wb.get_index(wb.get_sheet_by_title("2")); + sheet_index = wb.index(wb.sheet_by_title("2")); TS_ASSERT_EQUALS(sheet_index, 2); } void test_get_sheet_names() { xlnt::workbook wb; - wb.create_sheet().set_title("test_get_sheet_titles"); + wb.create_sheet().title("test_get_sheet_titles"); const std::vector expected_titles = { "Sheet1", "test_get_sheet_titles" }; - TS_ASSERT_EQUALS(wb.get_sheet_titles(), expected_titles); + TS_ASSERT_EQUALS(wb.sheet_titles(), expected_titles); } void test_add_named_range() @@ -156,10 +156,10 @@ public: xlnt::workbook wb; auto new_sheet = wb.create_sheet(); wb.create_named_range("test_nr", new_sheet, "A1"); - auto found_range = wb.get_named_range("test_nr"); - auto expected_range = new_sheet.get_range("A1"); + auto found_range = wb.named_range("test_nr"); + auto expected_range = new_sheet.range("A1"); TS_ASSERT_EQUALS(expected_range, found_range); - TS_ASSERT_THROWS(wb.get_named_range("test_nr2"), std::runtime_error); + TS_ASSERT_THROWS(wb.named_range("test_nr2"), std::runtime_error); } void test_remove_named_range() @@ -177,23 +177,23 @@ public: { xlnt::workbook wb; - wb.create_sheet().set_title("Sheet2"); - wb.create_sheet().set_title("Sheet3"); + wb.create_sheet().title("Sheet2"); + wb.create_sheet().title("Sheet3"); auto iter = wb.begin(); - TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet1"); - TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet2"); - TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet3"); + TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet1"); + TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet2"); + TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet3"); TS_ASSERT_EQUALS(iter, wb.end()); const auto wb_const = wb; auto const_iter = wb_const.begin(); - TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet1"); - TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet2"); - TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet3"); + TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet1"); + TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet2"); + TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet3"); TS_ASSERT_EQUALS(const_iter, wb_const.end()); } @@ -201,26 +201,26 @@ public: { xlnt::workbook wb; - wb.create_sheet().set_title("Sheet2"); - wb.create_sheet().set_title("Sheet3"); + wb.create_sheet().title("Sheet2"); + wb.create_sheet().title("Sheet3"); auto iter = wb.begin(); - TS_ASSERT_EQUALS((*iter).get_title(), "Sheet1"); + TS_ASSERT_EQUALS((*iter).title(), "Sheet1"); iter++; - TS_ASSERT_EQUALS((*iter).get_title(), "Sheet2"); + TS_ASSERT_EQUALS((*iter).title(), "Sheet2"); auto copy = wb.begin(); copy = iter; - TS_ASSERT_EQUALS((*iter).get_title(), "Sheet2"); + TS_ASSERT_EQUALS((*iter).title(), "Sheet2"); TS_ASSERT_EQUALS(iter, copy); iter++; - TS_ASSERT_EQUALS((*iter).get_title(), "Sheet3"); + TS_ASSERT_EQUALS((*iter).title(), "Sheet3"); TS_ASSERT_DIFFERS(iter, copy); copy++; - TS_ASSERT_EQUALS((*iter).get_title(), "Sheet3"); + TS_ASSERT_EQUALS((*iter).title(), "Sheet3"); TS_ASSERT_EQUALS(iter, copy); } @@ -228,41 +228,41 @@ public: { xlnt::manifest m; TS_ASSERT(!m.has_default_type("xml")); - TS_ASSERT_THROWS(m.get_default_type("xml"), xlnt::key_not_found); - TS_ASSERT(!m.has_relationship(xlnt::path("/"), xlnt::relationship::type::office_document)); - TS_ASSERT(m.get_relationships(xlnt::path("xl/workbook.xml")).empty()); + TS_ASSERT_THROWS(m.default_type("xml"), xlnt::key_not_found); + TS_ASSERT(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document)); + TS_ASSERT(m.relationships(xlnt::path("xl/workbook.xml")).empty()); } void test_memory() { xlnt::workbook wb, wb2; - wb.get_active_sheet().set_title("swap"); + wb.active_sheet().title("swap"); std::swap(wb, wb2); - TS_ASSERT_EQUALS(wb.get_active_sheet().get_title(), "Sheet1"); - TS_ASSERT_EQUALS(wb2.get_active_sheet().get_title(), "swap"); + TS_ASSERT_EQUALS(wb.active_sheet().title(), "Sheet1"); + TS_ASSERT_EQUALS(wb2.active_sheet().title(), "swap"); wb = wb2; - TS_ASSERT_EQUALS(wb.get_active_sheet().get_title(), "swap"); + TS_ASSERT_EQUALS(wb.active_sheet().title(), "swap"); } void test_clear() { xlnt::workbook wb; xlnt::style s = wb.create_style("s"); - wb.get_active_sheet().get_cell("B2").set_value("B2"); - wb.get_active_sheet().get_cell("B2").style(s); - TS_ASSERT(wb.get_active_sheet().get_cell("B2").has_style()); + wb.active_sheet().cell("B2").value("B2"); + wb.active_sheet().cell("B2").style(s); + TS_ASSERT(wb.active_sheet().cell("B2").has_style()); wb.clear_styles(); - TS_ASSERT(!wb.get_active_sheet().get_cell("B2").has_style()); + TS_ASSERT(!wb.active_sheet().cell("B2").has_style()); xlnt::format format = wb.create_format(); xlnt::font font; font.size(41); format.font(font, true); - wb.get_active_sheet().get_cell("B2").format(format); - TS_ASSERT(wb.get_active_sheet().get_cell("B2").has_format()); + wb.active_sheet().cell("B2").format(format); + TS_ASSERT(wb.active_sheet().cell("B2").has_format()); wb.clear_formats(); - TS_ASSERT(!wb.get_active_sheet().get_cell("B2").has_format()); + TS_ASSERT(!wb.active_sheet().cell("B2").has_format()); wb.clear(); - TS_ASSERT(wb.get_sheet_titles().empty()); + TS_ASSERT(wb.sheet_titles().empty()); } void test_comparison() @@ -275,7 +275,7 @@ public: const auto &wb_const = wb; //TODO these aren't tests... - wb_const.get_manifest(); + wb_const.manifest(); TS_ASSERT(wb.has_theme()); diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index e9fbfc07..de8657ca 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -106,6 +106,29 @@ void open_stream(std::ofstream &stream, const std::string &path) namespace xlnt { +bool workbook::has_core_property(const std::string &property_name) const +{ + return d_->core_properties_.count(property_name) > 0; +} + +template<> +void workbook::core_property(const std::string &property_name, const std::string value) +{ + d_->core_properties_[property_name] = value; +} + +template<> +void workbook::core_property(const std::string &property_name, const char *value) +{ + d_->core_properties_[property_name] = value; +} + +template<> +void workbook::core_property(const std::string &property_name, const datetime value) +{ + d_->core_properties_[property_name] = value.to_iso_string(); +} + workbook workbook::minimal() { auto impl = new detail::workbook_impl(); @@ -116,7 +139,7 @@ workbook workbook::minimal() wb.d_->manifest_.register_override_type(path("/workbook.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::office_document, uri("workbook.xml"), target_mode::internal); std::string title("1"); @@ -125,7 +148,7 @@ workbook workbook::minimal() wb.d_->manifest_.register_override_type(path("/sheet1.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); auto ws_rel = wb.d_->manifest_.register_relationship(uri("workbook.xml"), - relationship::type::worksheet, uri("sheet1.xml"), target_mode::internal); + relationship_type::worksheet, uri("sheet1.xml"), target_mode::internal); wb.d_->sheet_title_rel_id_map_[title] = ws_rel; return wb; @@ -138,71 +161,65 @@ workbook workbook::empty_excel() wb.d_->manifest_.register_override_type(path("/xl/workbook.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::office_document, uri("xl/workbook.xml"), target_mode::internal); wb.d_->manifest_.register_default_type("rels", "application/vnd.openxmlformats-package.relationships+xml"); wb.d_->manifest_.register_default_type("xml", "application/xml"); - wb.set_thumbnail(excel_thumbnail(), "jpeg", "image/jpeg"); + wb.thumbnail(excel_thumbnail(), "jpeg", "image/jpeg"); wb.d_->manifest_.register_override_type(path("/docProps/core.xml"), "application/vnd.openxmlformats-package.core-properties+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::core_properties, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::core_properties, uri("docProps/core.xml"), target_mode::internal); wb.d_->manifest_.register_override_type(path("/docProps/app.xml"), "application/vnd.openxmlformats-officedocument.extended-properties+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::extended_properties, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::extended_properties, uri("docProps/app.xml"), target_mode::internal); - wb.set_creator("Microsoft Office User"); - wb.set_last_modified_by("Microsoft Office User"); - wb.set_created(datetime(2016, 8, 12, 3, 16, 56)); - wb.set_modified(datetime(2016, 8, 12, 3, 17, 16)); - wb.set_application("Microsoft Macintosh Excel"); - wb.set_app_version("15.0300"); - wb.set_absolute_path(path("/Users/thomas/Development/xlnt/tests/data/xlsx/")); - wb.enable_x15(); + wb.core_property("Creator", "Microsoft Office User"); + wb.core_property("LastModifiedBy", "Microsoft Office User"); + wb.core_property("Created", datetime(2016, 8, 12, 3, 16, 56)); + wb.core_property("Modified", datetime(2016, 8, 12, 3, 17, 16)); + wb.core_property("Application", "Microsoft Macintosh Excel"); + wb.core_property("AppVersion", "15.0300"); - wb.d_->has_file_version_ = true; - wb.d_->file_version_.app_name = "xl"; - wb.d_->file_version_.last_edited = 6; - wb.d_->file_version_.lowest_edited = 6; - wb.d_->file_version_.rup_build = 26709; - - wb.d_->has_properties_ = true; - wb.d_->has_view_ = true; - wb.d_->has_arch_id_ = true; - wb.d_->has_calculation_properties_ = true; + auto file_version = detail::workbook_impl::file_version_t{"xl", 6, 6, 26709 }; + wb.d_->file_version_ = file_version; auto ws = wb.create_sheet(); - ws.enable_x14ac(); page_margins margins; - margins.set_left(0.7); - margins.set_right(0.7); - margins.set_top(0.75); - margins.set_bottom(0.75); - margins.set_header(0.3); - margins.set_footer(0.3); - ws.set_page_margins(margins); + margins.left(0.7); + margins.right(0.7); + margins.top(0.75); + margins.bottom(0.75); + margins.header(0.3); + margins.footer(0.3); + ws.page_margins(margins); ws.d_->has_dimension_ = true; ws.d_->has_format_properties_ = true; - ws.d_->has_view_ = true; + + sheet_view view; + ws.add_view(view); + + wb.d_->stylesheet_ = detail::stylesheet(); + auto &stylesheet = wb.d_->stylesheet_.get(); auto default_border = border().side(border_side::bottom, border::border_property()) .side(border_side::top, border::border_property()) .side(border_side::start, border::border_property()) .side(border_side::end, border::border_property()) .side(border_side::diagonal, border::border_property()); - wb.d_->stylesheet_.borders.push_back(default_border); + wb.d_->stylesheet_.get().borders.push_back(default_border); auto default_fill = fill(pattern_fill().type(pattern_fill_type::none)); - wb.d_->stylesheet_.fills.push_back(default_fill); + stylesheet.fills.push_back(default_fill); auto gray125_fill = pattern_fill().type(pattern_fill_type::gray125); - wb.d_->stylesheet_.fills.push_back(gray125_fill); + stylesheet.fills.push_back(gray125_fill); auto default_font = font() .name("Calibri") @@ -210,7 +227,7 @@ workbook workbook::empty_excel() .scheme("minor") .family(2) .color(theme_color(1)); - wb.d_->stylesheet_.fonts.push_back(default_font); + stylesheet.fonts.push_back(default_font); wb.create_style("Normal").builtin_id(0) .border(default_border, false) @@ -225,7 +242,7 @@ workbook workbook::empty_excel() .number_format(xlnt::number_format::general(), false) .style("Normal"); - wb.set_theme(theme()); + wb.theme(xlnt::theme()); return wb; } @@ -237,17 +254,17 @@ workbook workbook::empty_libre_office() wb.d_->manifest_.register_override_type(path("xl/workbook.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::office_document, uri("xl/workbook.xml"), target_mode::internal); wb.d_->manifest_.register_override_type(path("docProps/core.xml"), "application/vnd.openxmlformats-package.core-properties+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::core_properties, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::core_properties, uri("docProps/core.xml"), target_mode::internal); wb.d_->manifest_.register_override_type(path("docProps/app.xml"), "application/vnd.openxmlformats-officedocument.extended-properties+xml"); - wb.d_->manifest_.register_relationship(uri("/"), relationship::type::extended_properties, + wb.d_->manifest_.register_relationship(uri("/"), relationship_type::extended_properties, uri("docProps/app.xml"), target_mode::internal); wb.d_->manifest_.register_override_type(path("_rels/.rels"), @@ -261,26 +278,32 @@ workbook workbook::empty_libre_office() wb.d_->manifest_.register_override_type(path("xl/worksheets/sheet1.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); auto ws_rel = wb.d_->manifest_.register_relationship(uri("xl/workbook.xml"), - relationship::type::worksheet, uri("worksheets/sheet1.xml"), target_mode::internal); + relationship_type::worksheet, uri("worksheets/sheet1.xml"), target_mode::internal); wb.d_->sheet_title_rel_id_map_[title] = ws_rel; - auto ws = wb.get_sheet_by_index(0); + auto ws = wb.sheet_by_index(0); ws.d_->has_format_properties_ = true; - ws.d_->has_view_ = true; + + sheet_view view; + ws.add_view(view); + ws.d_->has_dimension_ = true; page_margins margins; - margins.set_left(0.7875); - margins.set_right(0.7875); - margins.set_top(1.05277777777778); - margins.set_bottom(1.05277777777778); - margins.set_header(0.7875); - margins.set_footer(0.7875); - ws.set_page_margins(margins); - ws.set_page_setup(page_setup()); - ws.get_header_footer().get_center_header().set_font_name("&C&\"Times New Roman\"&12&A"); - ws.get_header_footer().get_center_footer().set_font_name("&C&\"Times New Roman\"&12Page &B"); + margins.left(0.7875); + margins.right(0.7875); + margins.top(1.05277777777778); + margins.bottom(1.05277777777778); + margins.header(0.7875); + margins.footer(0.7875); + ws.page_margins(margins); + ws.page_setup(page_setup()); + ws.header_footer().center_header().font_name("&C&\"Times New Roman\"&12&A"); + ws.header_footer().center_footer().font_name("&C&\"Times New Roman\"&12Page &B"); ws.add_column_properties(1, column_properties()); + wb.d_->stylesheet_ = detail::stylesheet(); + auto &stylesheet = wb.d_->stylesheet_.get(); + auto default_alignment = xlnt::alignment() .horizontal(horizontal_alignment::general) .vertical(vertical_alignment::bottom) @@ -288,7 +311,7 @@ workbook workbook::empty_libre_office() .wrap(false) .indent(0) .shrink(false); - wb.d_->stylesheet_.alignments.push_back(default_alignment); + stylesheet.alignments.push_back(default_alignment); auto default_border = border().side(border_side::bottom, border::border_property()) .side(border_side::top, border::border_property()) @@ -296,29 +319,29 @@ workbook workbook::empty_libre_office() .side(border_side::end, border::border_property()) .side(border_side::diagonal, border::border_property()) .diagonal(diagonal_direction::neither); - wb.d_->stylesheet_.borders.push_back(default_border); + stylesheet.borders.push_back(default_border); auto default_fill = xlnt::fill(xlnt::pattern_fill().type(pattern_fill_type::none)); - wb.d_->stylesheet_.fills.push_back(default_fill); + stylesheet.fills.push_back(default_fill); auto gray125_fill = xlnt::fill(xlnt::pattern_fill().type(pattern_fill_type::gray125)); - wb.d_->stylesheet_.fills.push_back(gray125_fill); + stylesheet.fills.push_back(gray125_fill); auto default_font = font().name("Arial").size(10).family(2); - wb.d_->stylesheet_.fonts.push_back(default_font); + stylesheet.fonts.push_back(default_font); auto second_font = font().name("Arial").size(10).family(0); - wb.d_->stylesheet_.fonts.push_back(second_font); + stylesheet.fonts.push_back(second_font); auto default_number_format = xlnt::number_format(); - default_number_format.set_format_string("General"); - default_number_format.set_id(164); - wb.d_->stylesheet_.number_formats.push_back(default_number_format); + default_number_format.format_string("General"); + default_number_format.id(164); + stylesheet.number_formats.push_back(default_number_format); auto default_protection = xlnt::protection() .locked(true) .hidden(false); - wb.d_->stylesheet_.protections.push_back(default_protection); + stylesheet.protections.push_back(default_protection); wb.create_style("Normal").builtin_id(0).custom(false) .alignment(default_alignment, false) @@ -374,23 +397,14 @@ workbook workbook::empty_libre_office() .protection(default_protection, true) .style("Normal"); - wb.d_->has_file_version_ = true; - wb.d_->file_version_.app_name = "Calc"; - wb.d_->has_properties_ = true; - wb.d_->has_view_ = true; - wb.d_->has_calculation_properties_ = true; - wb.d_->application_ = "LibreOffice/5.1.4.2$Windows_x86 LibreOffice_project/f99d75f39f1c57ebdd7ffc5f42867c12031db97a"; - wb.d_->short_bools_ = false; + wb.core_property("Application", "LibreOffice/5.1.4.2$Windows_x86 LibreOffice_project/f99d75f39f1c57ebdd7ffc5f42867c12031db97a"); return wb; } workbook workbook::empty_numbers() { - auto impl = new detail::workbook_impl(); - workbook wb(impl); - - return wb; + return empty_excel(); } workbook::workbook() @@ -403,83 +417,86 @@ workbook::workbook(detail::workbook_impl *impl) : d_(impl) { if (impl != nullptr) { - d_->stylesheet_.parent = this; + if (d_->stylesheet_.is_set()) + { + d_->stylesheet_->parent = this; + } } } void workbook::register_app_properties_in_manifest() { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); - if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::extended_properties)) + if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::extended_properties)) { - get_manifest().register_override_type(path("/docProps/app.xml"), + manifest().register_override_type(path("/docProps/app.xml"), "application/vnd.openxmlformats-officedocument.extended-properties+xml"); - get_manifest().register_relationship(uri("/"), relationship::type::extended_properties, + manifest().register_relationship(uri("/"), relationship_type::extended_properties, uri("docProps/app.xml"), target_mode::internal); } } void workbook::register_core_properties_in_manifest() { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); - if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::core_properties)) + if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::core_properties)) { - get_manifest().register_override_type(path("/docProps/core.xml"), + manifest().register_override_type(path("/docProps/core.xml"), "application/vnd.openxmlformats-package.core-properties+xml"); - get_manifest().register_relationship(uri("/"), relationship::type::core_properties, + manifest().register_relationship(uri("/"), relationship_type::core_properties, uri("docProps/core.xml"), target_mode::internal); } } void workbook::register_shared_string_table_in_manifest() { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); - if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::shared_string_table)) + if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::shared_string_table)) { - get_manifest().register_override_type(constants::part_shared_strings(), + manifest().register_override_type(constants::part_shared_strings(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"); - get_manifest().register_relationship(wb_rel.get_target(), - relationship::type::shared_string_table, uri("sharedStrings.xml"), target_mode::internal); + manifest().register_relationship(wb_rel.target(), + relationship_type::shared_string_table, uri("sharedStrings.xml"), target_mode::internal); } } void workbook::register_stylesheet_in_manifest() { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); - if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::stylesheet)) + if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::stylesheet)) { - get_manifest().register_override_type(constants::part_styles(), + manifest().register_override_type(constants::part_styles(), "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"); - get_manifest().register_relationship(wb_rel.get_target(), - relationship::type::stylesheet, uri("styles.xml"), target_mode::internal); + manifest().register_relationship(wb_rel.target(), + relationship_type::stylesheet, uri("styles.xml"), target_mode::internal); } } void workbook::register_theme_in_manifest() { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); - if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::theme)) + if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::theme)) { - get_manifest().register_override_type(constants::part_theme(), + manifest().register_override_type(constants::part_theme(), "application/vnd.openxmlformats-officedocument.theme+xml"); - get_manifest().register_relationship(wb_rel.get_target(), - relationship::type::theme, uri("theme/theme1.xml"), target_mode::internal); + manifest().register_relationship(wb_rel.target(), + relationship_type::theme, uri("theme/theme1.xml"), target_mode::internal); } } void workbook::register_comments_in_manifest(worksheet ws) { - auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document); - auto ws_rel = get_manifest().get_relationship(wb_rel.get_target().get_path(), - d_->sheet_title_rel_id_map_.at(ws.get_title())); - path ws_path(ws_rel.get_source().get_path().parent().append(ws_rel.get_target().get_path())); + auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document); + auto ws_rel = manifest().relationship(wb_rel.target().path(), + d_->sheet_title_rel_id_map_.at(ws.title())); + path ws_path(ws_rel.source().path().parent().append(ws_rel.target().path())); - if (!get_manifest().has_relationship(ws_path, relationship_type::vml_drawing)) + if (!manifest().has_relationship(ws_path, relationship_type::vml_drawing)) { std::size_t file_number = 1; path filename("vmlDrawing1.vml"); @@ -489,14 +506,14 @@ void workbook::register_comments_in_manifest(worksheet ws) { filename_exists = false; - for (auto current_ws_rel : get_manifest().get_relationships(wb_rel.get_target().get_path(), xlnt::relationship_type::worksheet)) + for (auto current_ws_rel : manifest().relationships(wb_rel.target().path(), xlnt::relationship_type::worksheet)) { - path current_ws_path(current_ws_rel.get_source().get_path().parent().append(current_ws_rel.get_target().get_path())); - if (!get_manifest().has_relationship(current_ws_path, xlnt::relationship_type::vml_drawing)) continue; + path current_ws_path(current_ws_rel.source().path().parent().append(current_ws_rel.target().path())); + if (!manifest().has_relationship(current_ws_path, xlnt::relationship_type::vml_drawing)) continue; - for (auto current_ws_child_rel : get_manifest().get_relationships(current_ws_path, xlnt::relationship_type::vml_drawing)) + for (auto current_ws_child_rel : manifest().relationships(current_ws_path, xlnt::relationship_type::vml_drawing)) { - if (current_ws_child_rel.get_target().get_path() == path("../drawings").append(filename)) + if (current_ws_child_rel.target().path() == path("../drawings").append(filename)) { filename_exists = true; break; @@ -511,38 +528,38 @@ void workbook::register_comments_in_manifest(worksheet ws) } } - get_manifest().register_default_type("vml", + manifest().register_default_type("vml", "application/vnd.openxmlformats-officedocument.vmlDrawing"); const path relative_path(path("../drawings").append(filename)); - get_manifest().register_relationship(uri(ws_path.string()), - relationship::type::vml_drawing, uri(relative_path.string()), target_mode::internal); + manifest().register_relationship(uri(ws_path.string()), + relationship_type::vml_drawing, uri(relative_path.string()), target_mode::internal); } - if (!get_manifest().has_relationship(ws_path, relationship_type::comments)) + if (!manifest().has_relationship(ws_path, relationship_type::comments)) { std::size_t file_number = 1; path filename("comments1.xml"); while (true) { - if (!get_manifest().has_override_type(constants::package_xl().append(filename))) break; + if (!manifest().has_override_type(constants::package_xl().append(filename))) break; file_number++; filename = path("comments" + std::to_string(file_number) + ".xml"); } const path absolute_path(constants::package_xl().append(filename)); - get_manifest().register_override_type(absolute_path, + manifest().register_override_type(absolute_path, "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"); const path relative_path(path("..").append(filename)); - get_manifest().register_relationship(uri(ws_path.string()), - relationship::type::comments, uri(relative_path.string()), target_mode::internal); + manifest().register_relationship(uri(ws_path.string()), + relationship_type::comments, uri(relative_path.string()), target_mode::internal); } } -const worksheet workbook::get_sheet_by_title(const std::string &title) const +const worksheet workbook::sheet_by_title(const std::string &title) const { for (auto &impl : d_->worksheets_) { @@ -555,7 +572,7 @@ const worksheet workbook::get_sheet_by_title(const std::string &title) const throw key_not_found(); } -worksheet workbook::get_sheet_by_title(const std::string &title) +worksheet workbook::sheet_by_title(const std::string &title) { for (auto &impl : d_->worksheets_) { @@ -568,7 +585,24 @@ worksheet workbook::get_sheet_by_title(const std::string &title) throw key_not_found(); } -worksheet workbook::get_sheet_by_index(std::size_t index) +worksheet workbook::sheet_by_index(std::size_t index) +{ + if (index >= d_->worksheets_.size()) + { + throw invalid_parameter(); + } + + auto iter = d_->worksheets_.begin(); + + for (std::size_t i = 0; i < index; ++i) + { + ++iter; + } + + return worksheet(&*iter); +} + +const worksheet workbook::sheet_by_index(std::size_t index) const { auto iter = d_->worksheets_.begin(); @@ -579,18 +613,7 @@ worksheet workbook::get_sheet_by_index(std::size_t index) return worksheet(&*iter); } -const worksheet workbook::get_sheet_by_index(std::size_t index) const -{ - auto iter = d_->worksheets_.begin(); - - for (std::size_t i = 0; i < index; ++i, ++iter) - { - } - - return worksheet(&*iter); -} - -worksheet workbook::get_sheet_by_id(std::size_t id) +worksheet workbook::sheet_by_id(std::size_t id) { for (auto &impl : d_->worksheets_) { @@ -603,7 +626,7 @@ worksheet workbook::get_sheet_by_id(std::size_t id) throw key_not_found(); } -const worksheet workbook::get_sheet_by_id(std::size_t id) const +const worksheet workbook::sheet_by_id(std::size_t id) const { for (auto &impl : d_->worksheets_) { @@ -616,9 +639,10 @@ const worksheet workbook::get_sheet_by_id(std::size_t id) const throw key_not_found(); } -worksheet workbook::get_active_sheet() +worksheet workbook::active_sheet() { - return get_sheet_by_index(d_->active_sheet_index_); + return sheet_by_index(d_->active_sheet_index_.is_set() + ? d_->active_sheet_index_.get() : 0); } bool workbook::has_named_range(const std::string &name) const @@ -648,13 +672,13 @@ worksheet workbook::create_sheet() d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title)); - auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document); + auto workbook_rel = d_->manifest_.relationship(path("/"), relationship_type::office_document); uri relative_sheet_uri(path("worksheets").append(sheet_filename).string()); - auto absolute_sheet_path = path("/xl").append(relative_sheet_uri.get_path()); + auto absolute_sheet_path = path("/xl").append(relative_sheet_uri.path()); d_->manifest_.register_override_type(absolute_sheet_path, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); - auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(), - relationship::type::worksheet, relative_sheet_uri, target_mode::internal); + auto ws_rel = d_->manifest_.register_relationship(workbook_rel.target(), + relationship_type::worksheet, relative_sheet_uri, target_mode::internal); d_->sheet_title_rel_id_map_[title] = ws_rel; return worksheet(&d_->worksheets_.back()); @@ -666,7 +690,7 @@ void workbook::copy_sheet(worksheet to_copy) detail::worksheet_impl impl(*to_copy.d_); auto new_sheet = create_sheet(); - impl.title_ = new_sheet.get_title(); + impl.title_ = new_sheet.title(); *new_sheet.d_ = impl; } @@ -687,7 +711,7 @@ void workbook::copy_sheet(worksheet to_copy, std::size_t index) } } -std::size_t workbook::get_index(worksheet ws) +std::size_t workbook::index(worksheet ws) { auto match = std::find(begin(), end(), ws); @@ -706,7 +730,7 @@ void workbook::create_named_range(const std::string &name, worksheet range_owner void workbook::create_named_range(const std::string &name, worksheet range_owner, const range_reference &reference) { - get_sheet_by_title(range_owner.get_title()).create_named_range(name, reference); + sheet_by_title(range_owner.title()).create_named_range(name, reference); } void workbook::remove_named_range(const std::string &name) @@ -723,13 +747,13 @@ void workbook::remove_named_range(const std::string &name) throw key_not_found(); } -range workbook::get_named_range(const std::string &name) +range workbook::named_range(const std::string &name) { for (auto ws : *this) { if (ws.has_named_range(name)) { - return ws.get_named_range(name); + return ws.named_range(name); } } @@ -849,16 +873,6 @@ void workbook::load(const std::wstring &filename, const std::string &password) } #endif -void workbook::set_guess_types(bool guess) -{ - d_->guess_types_ = guess; -} - -bool workbook::get_guess_types() const -{ - return d_->guess_types_; -} - void workbook::remove_sheet(worksheet ws) { auto match_iter = std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), @@ -869,12 +883,12 @@ void workbook::remove_sheet(worksheet ws) throw invalid_parameter(); } - auto ws_rel_id = d_->sheet_title_rel_id_map_.at(ws.get_title()); - auto wb_rel = d_->manifest_.get_relationship(xlnt::path("/"), xlnt::relationship_type::office_document); - auto ws_rel = d_->manifest_.get_relationship(wb_rel.get_target().get_path(), ws_rel_id); - d_->manifest_.unregister_override_type(ws_rel.get_target().get_path()); - d_->manifest_.unregister_relationship(wb_rel.get_target(), ws_rel_id);; - d_->sheet_title_rel_id_map_.erase(ws.get_title()); + auto ws_rel_id = d_->sheet_title_rel_id_map_.at(ws.title()); + auto wb_rel = d_->manifest_.relationship(xlnt::path("/"), xlnt::relationship_type::office_document); + auto ws_rel = d_->manifest_.relationship(wb_rel.target().path(), ws_rel_id); + d_->manifest_.unregister_override_type(ws_rel.target().path()); + d_->manifest_.unregister_relationship(wb_rel.target(), ws_rel_id);; + d_->sheet_title_rel_id_map_.erase(ws.title()); d_->worksheets_.erase(match_iter); } @@ -894,7 +908,7 @@ worksheet workbook::create_sheet(std::size_t index) d_->worksheets_.pop_back(); } - return get_sheet_by_index(index); + return sheet_by_index(index); } worksheet workbook::create_sheet_with_rel(const std::string &title, const relationship &rel) @@ -902,12 +916,12 @@ worksheet workbook::create_sheet_with_rel(const std::string &title, const relati auto sheet_id = d_->worksheets_.size() + 1; d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title)); - auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document); - auto sheet_absoulute_path = workbook_rel.get_target().get_path().parent().append(rel.get_target().get_path()); + auto workbook_rel = d_->manifest_.relationship(path("/"), relationship_type::office_document); + auto sheet_absoulute_path = workbook_rel.target().path().parent().append(rel.target().path()); d_->manifest_.register_override_type(sheet_absoulute_path, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); - auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(), - relationship::type::worksheet, rel.get_target(), target_mode::internal); + auto ws_rel = d_->manifest_.register_relationship(workbook_rel.target(), + relationship_type::worksheet, rel.target(), target_mode::internal); d_->sheet_title_rel_id_map_[title] = ws_rel; return worksheet(&d_->worksheets_.back()); @@ -943,31 +957,31 @@ workbook::const_iterator workbook::cend() const return const_iterator(*this, d_->worksheets_.size()); } -std::vector workbook::get_sheet_titles() const +std::vector workbook::sheet_titles() const { std::vector names; for (auto ws : *this) { - names.push_back(ws.get_title()); + names.push_back(ws.title()); } return names; } -std::size_t workbook::get_sheet_count() const +std::size_t workbook::sheet_count() const { return d_->worksheets_.size(); } worksheet workbook::operator[](const std::string &name) { - return get_sheet_by_title(name); + return sheet_by_title(name); } worksheet workbook::operator[](std::size_t index) { - return get_sheet_by_index(index); + return sheet_by_index(index); } void workbook::clear() @@ -995,27 +1009,28 @@ void swap(workbook &left, workbook &right) { for (auto ws : left) { - ws.set_parent(left); + ws.parent(left); } - left.d_->stylesheet_.parent = &left; + left.d_->stylesheet_->parent = &left; } if (right.d_ != nullptr) { for (auto ws : right) { - ws.set_parent(right); + ws.parent(right); } - right.d_->stylesheet_.parent = &right; + right.d_->stylesheet_->parent = &right; } } workbook &workbook::operator=(workbook other) { swap(*this, other); - d_->stylesheet_.parent = this; + d_->stylesheet_->parent = this; + return *this; } @@ -1030,46 +1045,35 @@ workbook::workbook(const workbook &other) : workbook() for (auto ws : *this) { - ws.set_parent(*this); + ws.parent(*this); } - d_->stylesheet_.parent = this; + d_->stylesheet_->parent = this; } workbook::~workbook() { } -bool workbook::get_data_only() const -{ - return d_->data_only_; -} - -void workbook::set_data_only(bool data_only) -{ - d_->data_only_ = data_only; -} - bool workbook::has_theme() const { - return d_->has_theme_; + return d_->theme_.is_set(); } -const theme &workbook::get_theme() const +const theme &workbook::theme() const { - return d_->theme_; + return d_->theme_.get(); } -void workbook::set_theme(const theme &value) +void workbook::theme(const class theme &value) { register_theme_in_manifest(); - d_->has_theme_ = true; d_->theme_ = value; } -std::vector workbook::get_named_ranges() const +std::vector workbook::named_ranges() const { - std::vector named_ranges; + std::vector named_ranges; for (auto ws : *this) { @@ -1085,12 +1089,12 @@ std::vector workbook::get_named_ranges() const format workbook::create_format(bool default_format) { register_stylesheet_in_manifest(); - return d_->stylesheet_.create_format(default_format); + return d_->stylesheet_->create_format(default_format); } bool workbook::has_style(const std::string &name) const { - return d_->stylesheet_.has_style(name); + return d_->stylesheet_->has_style(name); } void workbook::clear_styles() @@ -1107,45 +1111,45 @@ void workbook::apply_to_cells(std::function f) { for (auto ws : *this) { - for (auto row = ws.get_lowest_row(); row <= ws.get_highest_row(); ++row) + for (auto row = ws.lowest_row(); row <= ws.highest_row(); ++row) { - for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); ++column) + for (auto column = ws.lowest_column(); column <= ws.highest_column(); ++column) { if (ws.has_cell(cell_reference(column, row))) { - f.operator()(ws.get_cell(cell_reference(column, row))); + f.operator()(ws.cell(cell_reference(column, row))); } } } } } -format workbook::get_format(std::size_t format_index) +format workbook::format(std::size_t format_index) { - return d_->stylesheet_.get_format(format_index); + return d_->stylesheet_->format(format_index); } -const format workbook::get_format(std::size_t format_index) const +const format workbook::format(std::size_t format_index) const { - return d_->stylesheet_.get_format(format_index); + return d_->stylesheet_->format(format_index); } -manifest &workbook::get_manifest() +manifest &workbook::manifest() { return d_->manifest_; } -const manifest &workbook::get_manifest() const +const manifest &workbook::manifest() const { return d_->manifest_; } -std::vector &workbook::get_shared_strings() +std::vector &workbook::shared_strings() { return d_->shared_strings_; } -const std::vector &workbook::get_shared_strings() const +const std::vector &workbook::shared_strings() const { return d_->shared_strings_; } @@ -1170,182 +1174,68 @@ bool workbook::contains(const std::string &sheet_title) const { for(auto ws : *this) { - if(ws.get_title() == sheet_title) return true; + if(ws.title() == sheet_title) return true; } return false; } -void workbook::set_thumbnail(const std::vector &thumbnail, +void workbook::thumbnail(const std::vector &thumbnail, const std::string &extension, const std::string &content_type) { - if (!d_->manifest_.has_relationship(path("/"), relationship::type::thumbnail)) + if (!d_->manifest_.has_relationship(path("/"), relationship_type::thumbnail)) { d_->manifest_.register_default_type(extension, content_type); - d_->manifest_.register_relationship(uri("/"), relationship::type::thumbnail, + d_->manifest_.register_relationship(uri("/"), relationship_type::thumbnail, uri("docProps/thumbnail.jpeg"), target_mode::internal); } - d_->thumbnail_.assign(thumbnail.begin(), thumbnail.end()); + auto thumbnail_rel = d_->manifest_.relationship(path("/"), relationship_type::thumbnail); + d_->images_[thumbnail_rel.target().to_string()] = thumbnail; } -const std::vector &workbook::get_thumbnail() const +const std::vector &workbook::thumbnail() const { - return d_->thumbnail_; + auto thumbnail_rel = d_->manifest_.relationship(path("/"), relationship_type::thumbnail); + return d_->images_.at(thumbnail_rel.target().to_string()); } style workbook::create_style(const std::string &name) { - return d_->stylesheet_.create_style(name); + return d_->stylesheet_->create_style(name); } style workbook::style(const std::string &name) { - return d_->stylesheet_.style(name); + return d_->stylesheet_->style(name); } const style workbook::style(const std::string &name) const { - return d_->stylesheet_.style(name); + return d_->stylesheet_->style(name); } -std::string workbook::get_application() const -{ - return d_->application_; -} - -void workbook::set_application(const std::string &application) -{ - d_->write_app_properties_ = true; - d_->application_ = application; -} - -calendar workbook::get_base_date() const +calendar workbook::base_date() const { return d_->base_date_; } -void workbook::set_base_date(calendar base_date) +void workbook::base_date(calendar base_date) { d_->base_date_ = base_date; } -std::string workbook::get_creator() const +bool workbook::has_title() const { - return d_->creator_; + return d_->title_.is_set(); } -void workbook::set_creator(const std::string &creator) +std::string workbook::title() const { - d_->creator_ = creator; + return d_->title_.get(); } -std::string workbook::get_last_modified_by() const -{ - return d_->last_modified_by_; -} - -void workbook::set_last_modified_by(const std::string &last_modified_by) -{ - d_->last_modified_by_ = last_modified_by; -} - -datetime workbook::get_created() const -{ - return d_->created_; -} - -void workbook::set_created(const datetime &when) -{ - d_->created_ = when; -} - -datetime workbook::get_modified() const -{ - return d_->modified_; -} - -void workbook::set_modified(const datetime &when) -{ - d_->modified_ = when; -} - -int workbook::get_doc_security() const -{ - return d_->doc_security_; -} - -void workbook::set_doc_security(int doc_security) -{ - d_->doc_security_ = doc_security; -} - -bool workbook::get_scale_crop() const -{ - return d_->scale_crop_; -} - -void workbook::set_scale_crop(bool scale_crop) -{ - d_->scale_crop_ = scale_crop; -} - -std::string workbook::get_company() const -{ - return d_->company_; -} - -void workbook::set_company(const std::string &company) -{ - d_->company_ = company; -} - -bool workbook::links_up_to_date() const -{ - return d_->links_up_to_date_; -} - -void workbook::set_links_up_to_date(bool links_up_to_date) -{ - d_->links_up_to_date_ = links_up_to_date; -} - -bool workbook::is_shared_doc() const -{ - return d_->shared_doc_; -} - -void workbook::set_shared_doc(bool shared_doc) -{ - d_->shared_doc_ = shared_doc; -} - -bool workbook::hyperlinks_changed() const -{ - return d_->hyperlinks_changed_; -} - -void workbook::set_hyperlinks_changed(bool hyperlinks_changed) -{ - d_->hyperlinks_changed_ = hyperlinks_changed; -} - -std::string workbook::get_app_version() const -{ - return d_->app_version_; -} - -void workbook::set_app_version(const std::string &version) -{ - d_->app_version_ = version; -} - -std::string workbook::get_title() const -{ - return d_->title_; -} - -void workbook::set_title(const std::string &title) +void workbook::title(const std::string &title) { d_->title_ = title; } @@ -1362,121 +1252,73 @@ const detail::workbook_impl &workbook::impl() const bool workbook::has_view() const { - return d_->has_view_; + return d_->view_.is_set(); } -workbook_view workbook::get_view() const +workbook_view workbook::view() const { - if (!d_->has_view_) + if (!d_->view_.is_set()) { throw invalid_attribute(); } - return d_->view_; + return d_->view_.get(); } -void workbook::set_view(const workbook_view &view) +void workbook::view(const workbook_view &view) { - d_->has_view_ = true; d_->view_ = view; } bool workbook::has_code_name() const { - return d_->has_code_name_; + return d_->code_name_.is_set(); } -std::string workbook::get_code_name() const +std::string workbook::code_name() const { - if (!d_->has_code_name_) + if (has_code_name()) { throw invalid_attribute(); } - return d_->code_name_; + return d_->code_name_.get(); } -void workbook::set_code_name(const std::string &code_name) +void workbook::code_name(const std::string &code_name) { d_->code_name_ = code_name; - d_->has_code_name_ = true; -} - -bool workbook::x15_enabled() const -{ - return d_->x15_; -} - -void workbook::enable_x15() -{ - d_->x15_ = true; -} - -void workbook::disable_x15() -{ - d_->x15_ = false; -} - -bool workbook::has_absolute_path() const -{ - return d_->has_absolute_path_; -} - -path workbook::get_absolute_path() const -{ - return d_->absolute_path_; -} - -void workbook::set_absolute_path(const path &absolute_path) -{ - d_->absolute_path_ = absolute_path; - d_->has_absolute_path_ = true; -} - -void workbook::clear_absolute_path() -{ - d_->absolute_path_ = path(); - d_->has_absolute_path_ = false; -} - -bool workbook::has_properties() const -{ - return d_->has_properties_; } bool workbook::has_file_version() const { - return d_->has_file_version_; + return d_->file_version_.is_set(); } -std::string workbook::get_app_name() const +std::string workbook::app_name() const { - return d_->file_version_.app_name; + return d_->file_version_.get().app_name; } -std::size_t workbook::get_last_edited() const +std::size_t workbook::last_edited() const { - return d_->file_version_.last_edited; + return d_->file_version_.get().last_edited; } -std::size_t workbook::get_lowest_edited() const +std::size_t workbook::lowest_edited() const { - return d_->file_version_.lowest_edited; + return d_->file_version_.get().lowest_edited; } -std::size_t workbook::get_rup_build() const +std::size_t workbook::rup_build() const { - return d_->file_version_.rup_build; + return d_->file_version_.get().rup_build; } -bool workbook::has_calculation_properties() const +template<> +std::string workbook::core_property(const std::string &property_name) const { - return d_->has_calculation_properties_; -} - -bool workbook::has_arch_id() const -{ - return d_->has_arch_id_; + return d_->core_properties_.at(property_name); } } // namespace xlnt diff --git a/source/worksheet/cell_iterator.cpp b/source/worksheet/cell_iterator.cpp index 12be1c34..9e8127f3 100644 --- a/source/worksheet/cell_iterator.cpp +++ b/source/worksheet/cell_iterator.cpp @@ -55,20 +55,20 @@ cell_iterator &cell_iterator::operator--() { if (order_ == major_order::row) { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); + current_cell_.column_index(current_cell_.column_index() - 1); - while (!ws_.has_cell(current_cell_) && current_cell_.get_column() > range_.get_top_left().get_column()) + while (!ws_.has_cell(current_cell_) && current_cell_.column() > range_.top_left().column()) { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); + current_cell_.column_index(current_cell_.column_index() - 1); } } else { - current_cell_.set_row(current_cell_.get_row() - 1); + current_cell_.row(current_cell_.row() - 1); - while (!ws_.has_cell(current_cell_) && current_cell_.get_row() > range_.get_top_left().get_row()) + while (!ws_.has_cell(current_cell_) && current_cell_.row() > range_.top_left().row()) { - current_cell_.set_row(current_cell_.get_row() - 1); + current_cell_.row(current_cell_.row() - 1); } } @@ -86,26 +86,26 @@ cell_iterator &cell_iterator::operator++() { if (order_ == major_order::row) { - if (current_cell_.get_column() <= range_.get_bottom_right().get_column()) + if (current_cell_.column() <= range_.bottom_right().column()) { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); + current_cell_.column_index(current_cell_.column_index() + 1); } - while (!ws_.has_cell(current_cell_) && current_cell_.get_column() <= range_.get_bottom_right().get_column()) + while (!ws_.has_cell(current_cell_) && current_cell_.column() <= range_.bottom_right().column()) { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); + current_cell_.column_index(current_cell_.column_index() + 1); } } else { - if (current_cell_.get_row() <= range_.get_bottom_right().get_row()) + if (current_cell_.row() <= range_.bottom_right().row()) { - current_cell_.set_row(current_cell_.get_row() + 1); + current_cell_.row(current_cell_.row() + 1); } - while (!ws_.has_cell(current_cell_) && current_cell_.get_row() <= range_.get_bottom_right().get_row()) + while (!ws_.has_cell(current_cell_) && current_cell_.row() <= range_.bottom_right().row()) { - current_cell_.set_row(current_cell_.get_row() + 1); + current_cell_.row(current_cell_.row() + 1); } } diff --git a/source/worksheet/cell_vector.cpp b/source/worksheet/cell_vector.cpp index de122114..c20c7ce5 100644 --- a/source/worksheet/cell_vector.cpp +++ b/source/worksheet/cell_vector.cpp @@ -29,55 +29,45 @@ namespace xlnt { cell_vector::iterator cell_vector::begin() { - return iterator(ws_, ref_.get_top_left(), ref_, order_); + return iterator(ws_, ref_.top_left(), ref_, order_); } cell_vector::iterator cell_vector::end() { if (order_ == major_order::row) { - auto past_end = ref_.get_bottom_right(); - past_end.set_column_index(past_end.get_column_index() + 1); + auto past_end = ref_.bottom_right(); + past_end.column_index(past_end.column_index() + 1); return iterator(ws_, past_end, ref_, order_); } - auto past_end = ref_.get_bottom_right(); - past_end.set_row(past_end.get_row() + 1); + auto past_end = ref_.bottom_right(); + past_end.row(past_end.row() + 1); return iterator(ws_, past_end, ref_, order_); } cell_vector::const_iterator cell_vector::cbegin() const { - return const_iterator(ws_, ref_.get_top_left(), order_); + return const_iterator(ws_, ref_.top_left(), order_); } cell_vector::const_iterator cell_vector::cend() const { if (order_ == major_order::row) { - auto past_end = ref_.get_bottom_right(); - past_end.set_column_index(past_end.get_column_index() + 1); + auto past_end = ref_.bottom_right(); + past_end.column_index(past_end.column_index() + 1); return const_iterator(ws_, past_end, order_); } - auto past_end = ref_.get_bottom_right(); - past_end.set_row(past_end.get_row() + 1); + auto past_end = ref_.bottom_right(); + past_end.row(past_end.row() + 1); return const_iterator(ws_, past_end, order_); } cell cell_vector::operator[](std::size_t cell_index) { - return get_cell(cell_index); -} - -std::size_t cell_vector::num_cells() const -{ - if (order_ == major_order::row) - { - return ref_.get_width() + 1; - } - - return ref_.get_height() + 1; + return cell(cell_index); } cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_order order) @@ -89,35 +79,37 @@ cell cell_vector::front() { if (order_ == major_order::row) { - return ws_.get_cell(ref_.get_top_left()); + return ws_.cell(ref_.top_left()); } - return ws_.get_cell(ref_.get_top_left()); + return ws_.cell(ref_.top_left()); } cell cell_vector::back() { if (order_ == major_order::row) { - return ws_.get_cell(ref_.get_bottom_right()); + return ws_.cell(ref_.bottom_right()); } - return ws_.get_cell(ref_.get_bottom_right()); + return ws_.cell(ref_.bottom_right()); } -cell cell_vector::get_cell(std::size_t index) +cell cell_vector::cell(std::size_t index) { if (order_ == major_order::row) { - return ws_.get_cell(ref_.get_top_left().make_offset(static_cast(index), 0)); + return ws_.cell(ref_.top_left().make_offset(static_cast(index), 0)); } - return ws_.get_cell(ref_.get_top_left().make_offset(0, static_cast(index))); + return ws_.cell(ref_.top_left().make_offset(0, static_cast(index))); } std::size_t cell_vector::length() const { - return num_cells(); + return order_ == major_order::row + ? ref_.width() + 1 + : ref_.height() + 1; } cell_vector::const_iterator cell_vector::begin() const diff --git a/source/worksheet/const_cell_iterator.cpp b/source/worksheet/const_cell_iterator.cpp index 7258b5a0..a6ed2baf 100644 --- a/source/worksheet/const_cell_iterator.cpp +++ b/source/worksheet/const_cell_iterator.cpp @@ -51,11 +51,11 @@ const_cell_iterator &const_cell_iterator::operator--() { if (order_ == major_order::row) { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); + current_cell_.column_index(current_cell_.column_index() - 1); } else { - current_cell_.set_row(current_cell_.get_row() - 1); + current_cell_.row(current_cell_.row() - 1); } return *this; @@ -72,11 +72,11 @@ const_cell_iterator &const_cell_iterator::operator++() { if (order_ == major_order::row) { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); + current_cell_.column_index(current_cell_.column_index() + 1); } else { - current_cell_.set_row(current_cell_.get_row() + 1); + current_cell_.row(current_cell_.row() + 1); } return *this; @@ -91,7 +91,7 @@ const_cell_iterator const_cell_iterator::operator++(int) const cell const_cell_iterator::operator*() const { - return ws_.get_cell(current_cell_); + return ws_.cell(current_cell_); } } // namespace xlnt diff --git a/source/worksheet/const_range_iterator.cpp b/source/worksheet/const_range_iterator.cpp index dade7bb9..44b800fa 100644 --- a/source/worksheet/const_range_iterator.cpp +++ b/source/worksheet/const_range_iterator.cpp @@ -29,7 +29,7 @@ namespace xlnt { const_range_iterator::const_range_iterator(const worksheet &ws, const range_reference &start_cell, major_order order) - : ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order) + : ws_(ws.d_), current_cell_(start_cell.top_left()), range_(start_cell), order_(order) { } @@ -52,11 +52,11 @@ const_range_iterator &const_range_iterator::operator--() { if (order_ == major_order::row) { - current_cell_.set_row(current_cell_.get_row() - 1); + current_cell_.row(current_cell_.row() - 1); } else { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); + current_cell_.column_index(current_cell_.column_index() - 1); } return *this; @@ -74,11 +74,11 @@ const_range_iterator &const_range_iterator::operator++() { if (order_ == major_order::row) { - current_cell_.set_row(current_cell_.get_row() + 1); + current_cell_.row(current_cell_.row() + 1); } else { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); + current_cell_.column_index(current_cell_.column_index() + 1); } return *this; @@ -96,13 +96,13 @@ const cell_vector const_range_iterator::operator*() const { if (order_ == major_order::row) { - range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(), - range_.get_bottom_right().get_column_index(), current_cell_.get_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_.get_column_index(), range_.get_top_left().get_row(), - current_cell_.get_column_index(), range_.get_bottom_right().get_row()); + 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_); } diff --git a/source/worksheet/footer.cpp b/source/worksheet/footer.cpp index a03b9396..677135db 100644 --- a/source/worksheet/footer.cpp +++ b/source/worksheet/footer.cpp @@ -25,25 +25,25 @@ namespace xlnt { -void footer::set_text(const std::string &text) +void footer::text(const std::string &text) { default_ = false; text_ = text; } -void footer::set_font_name(const std::string &font_name) +void footer::font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; } -void footer::set_font_size(std::size_t font_size) +void footer::font_size(std::size_t font_size) { default_ = false; font_size_ = font_size; } -void footer::set_font_color(const std::string &font_color) +void footer::font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; diff --git a/source/worksheet/header.cpp b/source/worksheet/header.cpp index 1f24c24e..096e4e9a 100644 --- a/source/worksheet/header.cpp +++ b/source/worksheet/header.cpp @@ -25,25 +25,25 @@ namespace xlnt { -void header::set_text(const std::string &text) +void header::text(const std::string &text) { default_ = false; text_ = text; } -void header::set_font_name(const std::string &font_name) +void header::font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; } -void header::set_font_size(std::size_t font_size) +void header::font_size(std::size_t font_size) { default_ = false; font_size_ = font_size; } -void header::set_font_color(const std::string &font_color) +void header::font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; diff --git a/source/worksheet/header_footer.cpp b/source/worksheet/header_footer.cpp index 313ff868..d086b863 100644 --- a/source/worksheet/header_footer.cpp +++ b/source/worksheet/header_footer.cpp @@ -25,27 +25,27 @@ namespace xlnt { -header &header_footer::get_left_header() +header &header_footer::left_header() { return left_header_; } -header &header_footer::get_center_header() +header &header_footer::center_header() { return center_header_; } -header &header_footer::get_right_header() +header &header_footer::right_header() { return right_header_; } -footer &header_footer::get_left_footer() +footer &header_footer::left_footer() { return left_footer_; } -footer &header_footer::get_center_footer() +footer &header_footer::center_footer() { return center_footer_; } -footer &header_footer::get_right_footer() +footer &header_footer::right_footer() { return right_footer_; } diff --git a/source/worksheet/page_margins.cpp b/source/worksheet/page_margins.cpp index 8fed3572..240d6518 100644 --- a/source/worksheet/page_margins.cpp +++ b/source/worksheet/page_margins.cpp @@ -29,62 +29,62 @@ page_margins::page_margins() { } -double page_margins::get_top() const +double page_margins::top() const { return top_; } -void page_margins::set_top(double top) +void page_margins::top(double top) { top_ = top; } -double page_margins::get_left() const +double page_margins::left() const { return left_; } -void page_margins::set_left(double left) +void page_margins::left(double left) { left_ = left; } -double page_margins::get_bottom() const +double page_margins::bottom() const { return bottom_; } -void page_margins::set_bottom(double bottom) +void page_margins::bottom(double bottom) { bottom_ = bottom; } -double page_margins::get_right() const +double page_margins::right() const { return right_; } -void page_margins::set_right(double right) +void page_margins::right(double right) { right_ = right; } -double page_margins::get_header() const +double page_margins::header() const { return header_; } -void page_margins::set_header(double header) +void page_margins::header(double header) { header_ = header; } -double page_margins::get_footer() const +double page_margins::footer() const { return footer_; } -void page_margins::set_footer(double footer) +void page_margins::footer(double footer) { footer_ = footer; } diff --git a/source/worksheet/page_setup.cpp b/source/worksheet/page_setup.cpp index 9206e182..535f9603 100644 --- a/source/worksheet/page_setup.cpp +++ b/source/worksheet/page_setup.cpp @@ -39,42 +39,42 @@ page_setup::page_setup() { } -page_break page_setup::get_break() const +page_break page_setup::page_break() const { return break_; } -void page_setup::set_break(page_break b) +void page_setup::page_break(enum page_break b) { break_ = b; } -sheet_state page_setup::get_sheet_state() const +sheet_state page_setup::sheet_state() const { return sheet_state_; } -void page_setup::set_sheet_state(sheet_state sheet_state) +void page_setup::sheet_state(enum sheet_state sheet_state) { sheet_state_ = sheet_state; } -paper_size page_setup::get_paper_size() const +paper_size page_setup::paper_size() const { return paper_size_; } -void page_setup::set_paper_size(paper_size paper_size) +void page_setup::paper_size(enum paper_size paper_size) { paper_size_ = paper_size; } -orientation page_setup::get_orientation() const +orientation page_setup::orientation() const { return orientation_; } -void page_setup::set_orientation(orientation orientation) +void page_setup::orientation(enum orientation orientation) { orientation_ = orientation; } @@ -84,7 +84,7 @@ bool page_setup::fit_to_page() const return fit_to_page_; } -void page_setup::set_fit_to_page(bool fit_to_page) +void page_setup::fit_to_page(bool fit_to_page) { fit_to_page_ = fit_to_page; } @@ -94,7 +94,7 @@ bool page_setup::fit_to_height() const return fit_to_height_; } -void page_setup::set_fit_to_height(bool fit_to_height) +void page_setup::fit_to_height(bool fit_to_height) { fit_to_height_ = fit_to_height; } @@ -104,37 +104,37 @@ bool page_setup::fit_to_width() const return fit_to_width_; } -void page_setup::set_fit_to_width(bool fit_to_width) +void page_setup::fit_to_width(bool fit_to_width) { fit_to_width_ = fit_to_width; } -void page_setup::set_horizontal_centered(bool horizontal_centered) +void page_setup::horizontal_centered(bool horizontal_centered) { horizontal_centered_ = horizontal_centered; } -bool page_setup::get_horizontal_centered() const +bool page_setup::horizontal_centered() const { return horizontal_centered_; } -void page_setup::set_vertical_centered(bool vertical_centered) +void page_setup::vertical_centered(bool vertical_centered) { vertical_centered_ = vertical_centered; } -bool page_setup::get_vertical_centered() const +bool page_setup::vertical_centered() const { return vertical_centered_; } -void page_setup::set_scale(double scale) +void page_setup::scale(double scale) { scale_ = scale; } -double page_setup::get_scale() const +double page_setup::scale() const { return scale_; } diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index 8171d48d..6cf0e643 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -40,10 +40,10 @@ range::~range() cell_vector range::operator[](std::size_t index) { - return get_vector(index); + return vector(index); } -range_reference range::get_reference() const +range_reference range::reference() const { return ref_; } @@ -52,10 +52,10 @@ std::size_t range::length() const { if (order_ == major_order::row) { - return ref_.get_bottom_right().get_row() - ref_.get_top_left().get_row() + 1; + return ref_.bottom_right().row() - ref_.top_left().row() + 1; } - return (ref_.get_bottom_right().get_column() - ref_.get_top_left().get_column()).index + 1; + return (ref_.bottom_right().column() - ref_.top_left().column()).index + 1; } bool range::operator==(const range &comparand) const @@ -63,51 +63,51 @@ bool range::operator==(const range &comparand) const return ref_ == comparand.ref_ && ws_ == comparand.ws_ && order_ == comparand.order_; } -cell_vector range::get_vector(std::size_t vector_index) +cell_vector range::vector(std::size_t vector_index) { if (order_ == major_order::row) { range_reference reference( - ref_.get_top_left().get_column_index(), - static_cast(static_cast(ref_.get_top_left().get_row()) + vector_index), - ref_.get_bottom_right().get_column_index(), - static_cast(static_cast(ref_.get_top_left().get_row()) + vector_index)); + ref_.top_left().column_index(), + static_cast(static_cast(ref_.top_left().row()) + vector_index), + ref_.bottom_right().column_index(), + static_cast(static_cast(ref_.top_left().row()) + vector_index)); return cell_vector(ws_, reference, order_); } range_reference reference( - static_cast(static_cast(ref_.get_top_left().get_column().index) + vector_index), - ref_.get_top_left().get_row(), - static_cast(static_cast(ref_.get_top_left().get_column().index) + vector_index), - ref_.get_bottom_right().get_row()); + static_cast(static_cast(ref_.top_left().column().index) + vector_index), + ref_.top_left().row(), + static_cast(static_cast(ref_.top_left().column().index) + vector_index), + ref_.bottom_right().row()); return cell_vector(ws_, reference, order_); } bool range::contains(const cell_reference &ref) { - return ref_.get_top_left().get_column_index() <= ref.get_column_index() && - ref_.get_bottom_right().get_column_index() >= ref.get_column_index() && - ref_.get_top_left().get_row() <= ref.get_row() && ref_.get_bottom_right().get_row() >= ref.get_row(); + return ref_.top_left().column_index() <= ref.column_index() && + ref_.bottom_right().column_index() >= ref.column_index() && + ref_.top_left().row() <= ref.row() && ref_.bottom_right().row() >= ref.row(); } -cell range::get_cell(const cell_reference &ref) +cell range::cell(const cell_reference &ref) { - return (*this)[ref.get_row() - 1][ref.get_column().index - 1]; + return (*this)[ref.row() - 1][ref.column().index - 1]; } range::iterator range::begin() { if (order_ == major_order::row) { - cell_reference top_right(ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row()); - range_reference row_range(ref_.get_top_left(), top_right); + cell_reference top_right(ref_.bottom_right().column_index(), ref_.top_left().row()); + range_reference row_range(ref_.top_left(), top_right); return iterator(ws_, row_range, ref_, order_); } - cell_reference bottom_left(ref_.get_top_left().get_column_index(), ref_.get_bottom_right().get_row()); - range_reference row_range(ref_.get_top_left(), bottom_left); + cell_reference bottom_left(ref_.top_left().column_index(), ref_.bottom_right().row()); + range_reference row_range(ref_.top_left(), bottom_left); return iterator(ws_, row_range, ref_, order_); } @@ -115,15 +115,15 @@ range::iterator range::end() { if (order_ == major_order::row) { - auto past_end_row_index = ref_.get_bottom_right().get_row() + 1; - cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index); - cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index); + auto past_end_row_index = ref_.bottom_right().row() + 1; + cell_reference bottom_left(ref_.top_left().column_index(), past_end_row_index); + cell_reference bottom_right(ref_.bottom_right().column_index(), past_end_row_index); return iterator(ws_, range_reference(bottom_left, bottom_right), ref_, order_); } - auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1; - cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row()); - cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row()); + auto past_end_column_index = ref_.bottom_right().column_index() + 1; + cell_reference top_right(past_end_column_index, ref_.top_left().row()); + cell_reference bottom_right(past_end_column_index, ref_.bottom_right().row()); return iterator(ws_, range_reference(top_right, bottom_right), ref_, order_); } @@ -131,13 +131,13 @@ range::const_iterator range::cbegin() const { if (order_ == major_order::row) { - cell_reference top_right(ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row()); - range_reference row_range(ref_.get_top_left(), top_right); + cell_reference top_right(ref_.bottom_right().column_index(), ref_.top_left().row()); + range_reference row_range(ref_.top_left(), top_right); return const_iterator(ws_, row_range, order_); } - cell_reference bottom_left(ref_.get_top_left().get_column_index(), ref_.get_bottom_right().get_row()); - range_reference row_range(ref_.get_top_left(), bottom_left); + cell_reference bottom_left(ref_.top_left().column_index(), ref_.bottom_right().row()); + range_reference row_range(ref_.top_left(), bottom_left); return const_iterator(ws_, row_range, order_); } @@ -145,15 +145,15 @@ range::const_iterator range::cend() const { if (order_ == major_order::row) { - auto past_end_row_index = ref_.get_bottom_right().get_row() + 1; - cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index); - cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index); + auto past_end_row_index = ref_.bottom_right().row() + 1; + cell_reference bottom_left(ref_.top_left().column_index(), past_end_row_index); + cell_reference bottom_right(ref_.bottom_right().column_index(), past_end_row_index); return const_iterator(ws_, range_reference(bottom_left, bottom_right), order_); } - auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1; - cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row()); - cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row()); + auto past_end_column_index = ref_.bottom_right().column_index() + 1; + cell_reference top_right(past_end_column_index, ref_.top_left().row()); + cell_reference bottom_right(past_end_column_index, ref_.bottom_right().row()); return const_iterator(ws_, range_reference(top_right, bottom_right), order_); } diff --git a/source/worksheet/range_iterator.cpp b/source/worksheet/range_iterator.cpp index cb925782..711f8ffd 100644 --- a/source/worksheet/range_iterator.cpp +++ b/source/worksheet/range_iterator.cpp @@ -32,18 +32,18 @@ cell_vector range_iterator::operator*() const { if (order_ == major_order::row) { - range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(), - range_.get_bottom_right().get_column_index(), current_cell_.get_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_.get_column_index(), range_.get_top_left().get_row(), - current_cell_.get_column_index(), range_.get_bottom_right().get_row()); + 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_); } range_iterator::range_iterator(worksheet &ws, const range_reference &start_cell, const range_reference &limits, major_order order) - : ws_(ws), current_cell_(start_cell.get_top_left()), range_(limits), order_(order) + : ws_(ws), current_cell_(start_cell.top_left()), range_(limits), order_(order) { } @@ -66,11 +66,11 @@ range_iterator &range_iterator::operator--() { if (order_ == major_order::row) { - current_cell_.set_row(current_cell_.get_row() - 1); + current_cell_.row(current_cell_.row() - 1); } else { - current_cell_.set_column_index(current_cell_.get_column_index() - 1); + current_cell_.column_index(current_cell_.column_index() - 1); } return *this; @@ -91,22 +91,22 @@ range_iterator &range_iterator::operator++() bool any_non_null = false; do { - current_cell_.set_row(current_cell_.get_row() + 1); + current_cell_.row(current_cell_.row() + 1); any_non_null = false; - for (auto column = current_cell_.get_column(); column <= range_.get_bottom_right().get_column(); column++) + for (auto column = current_cell_.column(); column <= range_.bottom_right().column(); column++) { - if (ws_.has_cell(cell_reference(column, current_cell_.get_row()))) + if (ws_.has_cell(cell_reference(column, current_cell_.row()))) { any_non_null = true; break; } } } - while (!any_non_null && current_cell_.get_row() <= range_.get_bottom_right().get_row()); + while (!any_non_null && current_cell_.row() <= range_.bottom_right().row()); } else { - current_cell_.set_column_index(current_cell_.get_column_index() + 1); + current_cell_.column_index(current_cell_.column_index() + 1); } return *this; diff --git a/source/worksheet/range_reference.cpp b/source/worksheet/range_reference.cpp index a4f2f5c6..f8a55ef6 100644 --- a/source/worksheet/range_reference.cpp +++ b/source/worksheet/range_reference.cpp @@ -75,19 +75,19 @@ range_reference range_reference::make_offset(int column_offset, int row_offset) bottom_right_.make_offset(column_offset, row_offset)); } -std::size_t range_reference::get_height() const +std::size_t range_reference::height() const { - return bottom_right_.get_row() - top_left_.get_row(); + return bottom_right_.row() - top_left_.row(); } -std::size_t range_reference::get_width() const +std::size_t range_reference::width() const { - return (bottom_right_.get_column() - top_left_.get_column()).index; + return (bottom_right_.column() - top_left_.column()).index; } bool range_reference::is_single_cell() const { - return get_width() == 0 && get_height() == 0; + return width() == 0 && height() == 0; } std::string range_reference::to_string() const @@ -105,19 +105,19 @@ bool range_reference::operator!=(const range_reference &comparand) const return comparand.top_left_ != top_left_ || comparand.bottom_right_ != bottom_right_; } -cell_reference range_reference::get_top_left() const +cell_reference range_reference::top_left() const { return top_left_; } -cell_reference range_reference::get_bottom_right() const +cell_reference range_reference::bottom_right() const { return bottom_right_; } -cell_reference &range_reference::get_top_left() +cell_reference &range_reference::top_left() { return top_left_; } -cell_reference &range_reference::get_bottom_right() +cell_reference &range_reference::bottom_right() { return bottom_right_; } diff --git a/source/worksheet/sheet_protection.cpp b/source/worksheet/sheet_protection.cpp index be3f3569..57277821 100644 --- a/source/worksheet/sheet_protection.cpp +++ b/source/worksheet/sheet_protection.cpp @@ -41,12 +41,12 @@ std::string int_to_hex(T i) namespace xlnt { -void sheet_protection::set_password(const std::string &password) +void sheet_protection::password(const std::string &password) { hashed_password_ = hash_password(password); } -std::string sheet_protection::get_hashed_password() const +std::string sheet_protection::hashed_password() const { return hashed_password_; } diff --git a/source/worksheet/tests/test_page_setup.hpp b/source/worksheet/tests/test_page_setup.hpp index 4b6e398b..bb14e60f 100644 --- a/source/worksheet/tests/test_page_setup.hpp +++ b/source/worksheet/tests/test_page_setup.hpp @@ -12,32 +12,32 @@ public: { xlnt::page_setup ps; - TS_ASSERT_EQUALS(ps.get_paper_size(), xlnt::paper_size::letter); - ps.set_paper_size(xlnt::paper_size::executive); - TS_ASSERT_EQUALS(ps.get_paper_size(), xlnt::paper_size::executive); + TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::letter); + ps.paper_size(xlnt::paper_size::executive); + TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::executive); - TS_ASSERT_EQUALS(ps.get_orientation(), xlnt::orientation::portrait); - ps.set_orientation(xlnt::orientation::landscape); - TS_ASSERT_EQUALS(ps.get_orientation(), xlnt::orientation::landscape); + TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::portrait); + ps.orientation(xlnt::orientation::landscape); + TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::landscape); TS_ASSERT(!ps.fit_to_page()); - ps.set_fit_to_page(true); + ps.fit_to_page(true); TS_ASSERT(ps.fit_to_page()); TS_ASSERT(!ps.fit_to_height()); - ps.set_fit_to_height(true); + ps.fit_to_height(true); TS_ASSERT(ps.fit_to_height()); TS_ASSERT(!ps.fit_to_width()); - ps.set_fit_to_width(true); + ps.fit_to_width(true); TS_ASSERT(ps.fit_to_width()); - TS_ASSERT(!ps.get_horizontal_centered()); - ps.set_horizontal_centered(true); - TS_ASSERT(ps.get_horizontal_centered()); + TS_ASSERT(!ps.horizontal_centered()); + ps.horizontal_centered(true); + TS_ASSERT(ps.horizontal_centered()); - TS_ASSERT(!ps.get_vertical_centered()); - ps.set_vertical_centered(true); - TS_ASSERT(ps.get_vertical_centered()); + TS_ASSERT(!ps.vertical_centered()); + ps.vertical_centered(true); + TS_ASSERT(ps.vertical_centered()); } }; diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 1610c268..1d5560b4 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -15,16 +15,16 @@ public: void test_new_worksheet() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - TS_ASSERT(ws.get_workbook() == wb); + auto ws = wb.active_sheet(); + TS_ASSERT(ws.workbook() == wb); } - void test_get_cell() + void test_cell() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(1, 1)); - TS_ASSERT_EQUALS(cell.get_reference(), "A1"); + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(1, 1)); + TS_ASSERT_EQUALS(cell.reference(), "A1"); } void test_invalid_cell() @@ -36,10 +36,10 @@ public: void test_worksheet_dimension() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_EQUALS("A1:A1", ws.calculate_dimension()); - ws.get_cell("B12").set_value("AAA"); + ws.cell("B12").value("AAA"); TS_ASSERT_EQUALS("B12:B12", ws.calculate_dimension()); } @@ -50,25 +50,25 @@ public: std::string coordinate = "A1"; xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("A1").set_value("first"); - ws.get_cell("C9").set_value("last"); + ws.cell("A1").value("first"); + ws.cell("C9").value("last"); TS_ASSERT_EQUALS(ws.calculate_dimension(), "A1:C9"); - TS_ASSERT_EQUALS(ws.rows()[row][column].get_reference(), coordinate); + TS_ASSERT_EQUALS(ws.rows()[row][column].reference(), coordinate); row = 8; column = 2; coordinate = "C9"; - TS_ASSERT_EQUALS(ws.rows()[row][column].get_reference(), coordinate); + TS_ASSERT_EQUALS(ws.rows()[row][column].reference(), coordinate); } void test_iter_rows() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); const std::vector> expected = { @@ -87,7 +87,7 @@ public: for(auto cell : row) { - TS_ASSERT_EQUALS(cell.get_reference(), *expected_cell_iter); + TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter); expected_cell_iter++; } @@ -98,7 +98,7 @@ public: void test_iter_rows_offset() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto rows = ws.rows("A1:C4", 1, 3); const std::vector> expected = @@ -117,7 +117,7 @@ public: for(auto cell : row) { - TS_ASSERT_EQUALS(cell.get_reference(), *expected_cell_iter); + TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter); expected_cell_iter++; } @@ -128,7 +128,7 @@ public: void test_iter_rows_offset_int_int() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto rows = ws.rows(1, 3); const std::vector> expected = @@ -147,7 +147,7 @@ public: for (auto cell : row) { - TS_ASSERT_EQUALS(cell.get_reference(), *expected_cell_iter); + TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter); expected_cell_iter++; } @@ -158,25 +158,25 @@ public: void test_get_named_range() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); wb.create_named_range("test_range", ws, "C5"); - auto xlrange = ws.get_named_range("test_range"); + auto xlrange = ws.named_range("test_range"); TS_ASSERT_EQUALS(1, xlrange.length()); - TS_ASSERT_EQUALS(1, xlrange[0].num_cells()); - TS_ASSERT_EQUALS(5, xlrange[0][0].get_row()); + TS_ASSERT_EQUALS(1, xlrange[0].length()); + TS_ASSERT_EQUALS(5, xlrange[0][0].row()); ws.create_named_range("test_range2", "C6"); - auto xlrange2 = ws.get_named_range("test_range2"); + auto xlrange2 = ws.named_range("test_range2"); TS_ASSERT_EQUALS(1, xlrange2.length()); - TS_ASSERT_EQUALS(1, xlrange2[0].num_cells()); - TS_ASSERT_EQUALS(6, xlrange2[0][0].get_row()); + TS_ASSERT_EQUALS(1, xlrange2[0].length()); + TS_ASSERT_EQUALS(6, xlrange2[0][0].row()); } void test_get_bad_named_range() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - TS_ASSERT_THROWS(ws.get_named_range("bad_range"), xlnt::key_not_found); + auto ws = wb.active_sheet(); + TS_ASSERT_THROWS(ws.named_range("bad_range"), xlnt::key_not_found); } void test_get_named_range_wrong_sheet() @@ -187,22 +187,22 @@ public: auto ws1 = wb[0]; auto ws2 = wb[1]; wb.create_named_range("wrong_sheet_range", ws1, "C5"); - TS_ASSERT_THROWS(ws2.get_named_range("wrong_sheet_range"), xlnt::key_not_found); + TS_ASSERT_THROWS(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found); } void test_remove_named_range_bad() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_THROWS(ws.remove_named_range("bad_range"), std::runtime_error); } void test_cell_alternate_coordinates() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - auto cell = ws.get_cell(xlnt::cell_reference(4, 8)); - TS_ASSERT_EQUALS(cell.get_reference(), "D8"); + auto ws = wb.active_sheet(); + auto cell = ws.cell(xlnt::cell_reference(4, 8)); + TS_ASSERT_EQUALS(cell.reference(), "D8"); } // void test_cell_insufficient_coordinates() {} @@ -210,11 +210,11 @@ public: void test_cell_range_name() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); wb.create_named_range("test_range_single", ws, "B12"); - auto c_range_name = ws.get_named_range("test_range_single"); - auto c_range_coord = ws.get_range("B12"); - auto c_cell = ws.get_cell("B12"); + auto c_range_name = ws.named_range("test_range_single"); + auto c_range_coord = ws.range("B12"); + auto c_cell = ws.cell("B12"); TS_ASSERT_EQUALS(c_range_coord, c_range_name); TS_ASSERT(c_range_coord[0][0] == c_cell); } @@ -222,37 +222,37 @@ public: void test_hyperlink_value() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.get_cell("A1").set_hyperlink("http://test.com"); - TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value()); - ws.get_cell("A1").set_value("test"); - TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS(ws.get_cell("A1").get_hyperlink(), "http://test.com"); + auto ws = wb.active_sheet(); + ws.cell("A1").hyperlink("http://test.com"); + TS_ASSERT_EQUALS("http://test.com", ws.cell("A1").value()); + ws.cell("A1").value("test"); + TS_ASSERT_EQUALS("test", ws.cell("A1").value()); + TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com"); } void test_append() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append(std::vector {"value"}); - TS_ASSERT_EQUALS("value", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("value", ws.cell("A1").value()); } void test_append_list() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append(std::vector {"This is A1", "This is B1"}); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is B1", ws.get_cell("B1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value()); + TS_ASSERT_EQUALS("This is B1", ws.cell("B1").value()); } void test_append_dict_letter() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); const std::unordered_map dict_letter = { @@ -262,14 +262,14 @@ public: ws.append(dict_letter); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value()); + TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value()); } void test_append_dict_index() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); const std::unordered_map dict_index = { @@ -279,8 +279,8 @@ public: ws.append(dict_index); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value()); + TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value()); } void test_append_iterator() @@ -293,35 +293,35 @@ public: } xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append(range.begin(), range.end()); - TS_ASSERT_EQUALS(ws[xlnt::cell_reference("AD1")].get_value(), 29); + TS_ASSERT_EQUALS(ws[xlnt::cell_reference("AD1")].value(), 29); } void test_append_2d_list() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append(std::vector {"This is A1", "This is B1"}); ws.append(std::vector {"This is A2", "This is B2"}); - auto vals = ws.get_range("A1:B2"); + auto vals = ws.range("A1:B2"); - TS_ASSERT_EQUALS(vals[0][0].get_value(), "This is A1"); - TS_ASSERT_EQUALS(vals[0][1].get_value(), "This is B1"); - TS_ASSERT_EQUALS(vals[1][0].get_value(), "This is A2"); - TS_ASSERT_EQUALS(vals[1][1].get_value(), "This is B2"); + TS_ASSERT_EQUALS(vals[0][0].value(), "This is A1"); + TS_ASSERT_EQUALS(vals[0][1].value(), "This is B1"); + TS_ASSERT_EQUALS(vals[1][0].value(), "This is A2"); + TS_ASSERT_EQUALS(vals[1][1].value(), "This is B2"); } void test_rows() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("A1").set_value("first"); - ws.get_cell("C9").set_value("last"); + ws.cell("A1").value("first"); + ws.cell("C9").value("last"); auto rows = ws.rows(); @@ -330,15 +330,15 @@ public: auto first_row = rows[0]; auto last_row = rows[8]; - TS_ASSERT_EQUALS(first_row[0].get_value(), "first"); - TS_ASSERT_EQUALS(first_row[0].get_reference(), "A1"); - TS_ASSERT_EQUALS(last_row[2].get_value(), "last"); + TS_ASSERT_EQUALS(first_row[0].value(), "first"); + TS_ASSERT_EQUALS(first_row[0].reference(), "A1"); + TS_ASSERT_EQUALS(last_row[2].value(), "last"); } void test_no_rows() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_EQUALS(ws.rows().length(), 1); TS_ASSERT_EQUALS(ws.rows()[0].length(), 1); @@ -347,7 +347,7 @@ public: void test_no_cols() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_EQUALS(ws.columns().length(), 1); TS_ASSERT_EQUALS(ws.columns()[0].length(), 1); @@ -356,9 +356,9 @@ public: void test_one_cell() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - auto cell = ws.get_cell("A1"); + auto cell = ws.cell("A1"); TS_ASSERT_EQUALS(ws.columns().length(), 1); TS_ASSERT_EQUALS(ws.columns()[0].length(), 1); @@ -370,89 +370,89 @@ public: void test_cols() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("A1").set_value("first"); - ws.get_cell("C9").set_value("last"); + ws.cell("A1").value("first"); + ws.cell("C9").value("last"); auto cols = ws.columns(); TS_ASSERT_EQUALS(cols.length(), 3); - TS_ASSERT_EQUALS(cols[0][0].get_value(), "first"); - TS_ASSERT_EQUALS(cols[2][8].get_value(), "last"); + TS_ASSERT_EQUALS(cols[0][0].value(), "first"); + TS_ASSERT_EQUALS(cols[2][8].value(), "last"); } void test_auto_filter() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.auto_filter(ws.get_range("a1:f1")); - TS_ASSERT_EQUALS(ws.get_auto_filter(), "A1:F1"); + ws.auto_filter(ws.range("a1:f1")); + TS_ASSERT_EQUALS(ws.auto_filter(), "A1:F1"); - ws.unset_auto_filter(); + ws.clear_auto_filter(); TS_ASSERT_EQUALS(ws.has_auto_filter(), false); ws.auto_filter("c1:g9"); - TS_ASSERT_EQUALS(ws.get_auto_filter(), "C1:G9"); + TS_ASSERT_EQUALS(ws.auto_filter(), "C1:G9"); } void test_getitem() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); xlnt::cell cell = ws[xlnt::cell_reference("A1")]; - TS_ASSERT_EQUALS(cell.get_reference().to_string(), "A1"); - TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::null); + TS_ASSERT_EQUALS(cell.reference().to_string(), "A1"); + TS_ASSERT_EQUALS(cell.data_type(), xlnt::cell::type::null); } void test_setitem() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws[xlnt::cell_reference("A12")].set_value(5); - TS_ASSERT(ws[xlnt::cell_reference("A12")].get_value() == 5); + auto ws = wb.active_sheet(); + ws[xlnt::cell_reference("A12")].value(5); + TS_ASSERT(ws[xlnt::cell_reference("A12")].value() == 5); } void test_getslice() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto cell_range = ws("A1", "B2"); - TS_ASSERT_EQUALS(cell_range[0][0], ws.get_cell("A1")); - TS_ASSERT_EQUALS(cell_range[1][0], ws.get_cell("A2")); - TS_ASSERT_EQUALS(cell_range[0][1], ws.get_cell("B1")); - TS_ASSERT_EQUALS(cell_range[1][1], ws.get_cell("B2")); + TS_ASSERT_EQUALS(cell_range[0][0], ws.cell("A1")); + TS_ASSERT_EQUALS(cell_range[1][0], ws.cell("A2")); + TS_ASSERT_EQUALS(cell_range[0][1], ws.cell("B1")); + TS_ASSERT_EQUALS(cell_range[1][1], ws.cell("B2")); } void test_freeze() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.freeze_panes(ws.get_cell("b2")); - TS_ASSERT_EQUALS(ws.get_frozen_panes(), "B2"); + ws.freeze_panes(ws.cell("b2")); + TS_ASSERT_EQUALS(ws.frozen_panes(), "B2"); ws.unfreeze_panes(); TS_ASSERT(!ws.has_frozen_panes()); ws.freeze_panes("c5"); - TS_ASSERT_EQUALS(ws.get_frozen_panes(), "C5"); + TS_ASSERT_EQUALS(ws.frozen_panes(), "C5"); - ws.freeze_panes(ws.get_cell("A1")); + ws.freeze_panes(ws.cell("A1")); TS_ASSERT(!ws.has_frozen_panes()); } void test_merged_cells_lookup() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.get_cell("A2").set_value("test"); + auto ws = wb.active_sheet(); + ws.cell("A2").value("test"); ws.merge_cells("A1:N50"); - auto all_merged = ws.get_merged_ranges(); + auto all_merged = ws.merged_ranges(); TS_ASSERT_EQUALS(all_merged.size(), 1); - auto merged = ws.get_range(all_merged[0]); + auto merged = ws.range(all_merged[0]); TS_ASSERT(merged.contains("A1")); TS_ASSERT(merged.contains("N50")); TS_ASSERT(!merged.contains("A51")); @@ -463,35 +463,35 @@ public: void test_merged_cell_ranges() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - TS_ASSERT_EQUALS(ws.get_merged_ranges().size(), 0); + auto ws = wb.active_sheet(); + TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0); } void test_merge_range_string() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.get_cell("A1").set_value(1); - ws.get_cell("D4").set_value(16); + auto ws = wb.active_sheet(); + ws.cell("A1").value(1); + ws.cell("D4").value(16); ws.merge_cells("A1:D4"); std::vector expected = { xlnt::range_reference("A1:D4") }; - TS_ASSERT_EQUALS(ws.get_merged_ranges(), expected); - TS_ASSERT(!ws.get_cell("D4").has_value()); + TS_ASSERT_EQUALS(ws.merged_ranges(), expected); + TS_ASSERT(!ws.cell("D4").has_value()); } void test_merge_coordinate() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.merge_cells(1, 1, 4, 4); std::vector expected = { xlnt::range_reference("A1:D4") }; - TS_ASSERT_EQUALS(ws.get_merged_ranges(), expected); + TS_ASSERT_EQUALS(ws.merged_ranges(), expected); } void test_unmerge_bad() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_THROWS(ws.unmerge_cells("A1:D3"), std::runtime_error); } @@ -499,156 +499,156 @@ public: void test_unmerge_range_string() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.merge_cells("A1:D4"); - TS_ASSERT_EQUALS(ws.get_merged_ranges().size(), 1); + TS_ASSERT_EQUALS(ws.merged_ranges().size(), 1); ws.unmerge_cells("A1:D4"); - TS_ASSERT_EQUALS(ws.get_merged_ranges().size(), 0); + TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0); } void test_unmerge_coordinate() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.merge_cells("A1:D4"); - TS_ASSERT_EQUALS(ws.get_merged_ranges().size(), 1); + TS_ASSERT_EQUALS(ws.merged_ranges().size(), 1); ws.unmerge_cells(1, 1, 4, 4); - TS_ASSERT_EQUALS(ws.get_merged_ranges().size(), 0); + TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0); } void test_print_titles_old() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.set_print_title_rows(3); - TS_ASSERT_EQUALS(ws.get_print_titles(), "Sheet1!1:3"); + auto ws = wb.active_sheet(); + ws.print_title_rows(3); + TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:3"); auto ws2 = wb.create_sheet(); - ws2.set_print_title_cols(4); - TS_ASSERT_EQUALS(ws2.get_print_titles(), "Sheet2!A:D"); + ws2.print_title_cols(4); + TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:D"); } void test_print_titles_new() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.set_print_title_rows(4); - TS_ASSERT_EQUALS(ws.get_print_titles(), "Sheet1!1:4"); + auto ws = wb.active_sheet(); + ws.print_title_rows(4); + TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:4"); auto ws2 = wb.create_sheet(); - ws2.set_print_title_cols("F"); - TS_ASSERT_EQUALS(ws2.get_print_titles(), "Sheet2!A:F"); + ws2.print_title_cols("F"); + TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:F"); auto ws3 = wb.create_sheet(); - ws3.set_print_title_rows(2, 3); - ws3.set_print_title_cols("C", "D"); - TS_ASSERT_EQUALS(ws3.get_print_titles(), "Sheet3!2:3,Sheet3!C:D"); + ws3.print_title_rows(2, 3); + ws3.print_title_cols("C", "D"); + TS_ASSERT_EQUALS(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D"); } void test_print_area() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.set_print_area("A1:F5"); - TS_ASSERT_EQUALS(ws.get_print_area(), "$A$1:$F$5"); + auto ws = wb.active_sheet(); + ws.print_area("A1:F5"); + TS_ASSERT_EQUALS(ws.print_area(), "$A$1:$F$5"); } void test_freeze_panes_horiz() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.freeze_panes("A4"); - auto view = ws.get_view(); - TS_ASSERT_EQUALS(view.get_selections().size(), 1); - TS_ASSERT_EQUALS(view.get_selections()[0].get_active_cell(), "A1"); - TS_ASSERT_EQUALS(view.get_selections()[0].get_pane(), xlnt::pane_corner::bottom_left); - TS_ASSERT_EQUALS(view.get_selections()[0].get_sqref(), "A1"); - TS_ASSERT_EQUALS(view.get_pane().active_pane, xlnt::pane_corner::bottom_left); - TS_ASSERT_EQUALS(view.get_pane().state, xlnt::pane_state::frozen); - TS_ASSERT_EQUALS(view.get_pane().top_left_cell, "A4"); - TS_ASSERT_EQUALS(view.get_pane().y_split, 3); + auto view = ws.view(); + TS_ASSERT_EQUALS(view.selections().size(), 2); + TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "A3"); + TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::bottom_left); + TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1"); + TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_left); + TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen); + TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "A4"); + TS_ASSERT_EQUALS(view.pane().y_split, 3); } void test_freeze_panes_vert() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.freeze_panes("D1"); - auto view = ws.get_view(); - TS_ASSERT_EQUALS(view.get_selections().size(), 1); - TS_ASSERT_EQUALS(view.get_selections()[0].get_active_cell(), "A1"); - TS_ASSERT_EQUALS(view.get_selections()[0].get_pane(), xlnt::pane_corner::top_right); - TS_ASSERT_EQUALS(view.get_selections()[0].get_sqref(), "A1"); - TS_ASSERT_EQUALS(view.get_pane().active_pane, xlnt::pane_corner::top_right); - TS_ASSERT_EQUALS(view.get_pane().state, xlnt::pane_state::frozen); - TS_ASSERT_EQUALS(view.get_pane().top_left_cell, "D1"); - TS_ASSERT_EQUALS(view.get_pane().x_split, 3); + auto view = ws.view(); + TS_ASSERT_EQUALS(view.selections().size(), 2); + TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "C1"); + TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right); + TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1"); + TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::top_right); + TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen); + TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D1"); + TS_ASSERT_EQUALS(view.pane().x_split, 3); } void test_freeze_panes_both() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.freeze_panes("D4"); - auto view = ws.get_view(); - TS_ASSERT_EQUALS(view.get_selections().size(), 3); - TS_ASSERT_EQUALS(view.get_selections()[0].get_pane(), xlnt::pane_corner::top_right); - TS_ASSERT_EQUALS(view.get_selections()[1].get_pane(), xlnt::pane_corner::bottom_left); - TS_ASSERT_EQUALS(view.get_selections()[2].get_active_cell(), "A1"); - TS_ASSERT_EQUALS(view.get_selections()[2].get_pane(), xlnt::pane_corner::bottom_right); - TS_ASSERT_EQUALS(view.get_selections()[2].get_sqref(), "A1"); - TS_ASSERT_EQUALS(view.get_pane().active_pane, xlnt::pane_corner::bottom_right); - TS_ASSERT_EQUALS(view.get_pane().state, xlnt::pane_state::frozen); - TS_ASSERT_EQUALS(view.get_pane().top_left_cell, "D4"); - TS_ASSERT_EQUALS(view.get_pane().x_split, 3); - TS_ASSERT_EQUALS(view.get_pane().y_split, 3); + auto view = ws.view(); + TS_ASSERT_EQUALS(view.selections().size(), 3); + TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right); + TS_ASSERT_EQUALS(view.selections()[1].pane(), xlnt::pane_corner::bottom_left); + TS_ASSERT_EQUALS(view.selections()[2].active_cell(), "D4"); + TS_ASSERT_EQUALS(view.selections()[2].pane(), xlnt::pane_corner::bottom_right); + TS_ASSERT_EQUALS(view.selections()[2].sqref(), "A1"); + TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_right); + TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen); + TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D4"); + TS_ASSERT_EQUALS(view.pane().x_split, 3); + TS_ASSERT_EQUALS(view.pane().y_split, 3); } void test_min_column() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - TS_ASSERT_EQUALS(ws.get_lowest_column(), 1); + auto ws = wb.active_sheet(); + TS_ASSERT_EQUALS(ws.lowest_column(), 1); } void test_max_column() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws[xlnt::cell_reference("F1")].set_value(10); - ws[xlnt::cell_reference("F2")].set_value(32); - ws[xlnt::cell_reference("F3")].set_formula("=F1+F2"); - ws[xlnt::cell_reference("A4")].set_formula("=A1+A2+A3"); - TS_ASSERT_EQUALS(ws.get_highest_column(), 6); + auto ws = wb.active_sheet(); + ws[xlnt::cell_reference("F1")].value(10); + ws[xlnt::cell_reference("F2")].value(32); + ws[xlnt::cell_reference("F3")].formula("=F1+F2"); + ws[xlnt::cell_reference("A4")].formula("=A1+A2+A3"); + TS_ASSERT_EQUALS(ws.highest_column(), 6); } void test_min_row() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - TS_ASSERT_EQUALS(ws.get_lowest_row(), 1); + auto ws = wb.active_sheet(); + TS_ASSERT_EQUALS(ws.lowest_row(), 1); } void test_max_row() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append(); ws.append(std::vector { 5 }); ws.append(); ws.append(std::vector { 4 }); - TS_ASSERT_EQUALS(ws.get_highest_row(), 4); + TS_ASSERT_EQUALS(ws.highest_row(), 4); } void test_const_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -658,17 +658,17 @@ public: const auto first_row = *rows.begin(); const auto first_cell = *first_row.begin(); - TS_ASSERT_EQUALS(first_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(first_cell.value(), "A1"); const auto last_row = *(--rows.end()); const auto last_cell = *(--last_row.end()); - TS_ASSERT_EQUALS(last_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(last_cell.value(), "C2"); for (const auto row : rows) { for (const auto cell : row) { - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -676,7 +676,7 @@ public: void test_const_reverse_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -686,7 +686,7 @@ public: const auto first_row = *rows.rbegin(); const auto first_cell = *first_row.rbegin(); - TS_ASSERT_EQUALS(first_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(first_cell.value(), "C2"); auto row_iter = rows.rend(); row_iter--; @@ -694,7 +694,7 @@ public: auto cell_iter = last_row.rend(); cell_iter--; const auto last_cell = *cell_iter; - TS_ASSERT_EQUALS(last_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(last_cell.value(), "A1"); for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ws_iter++) { @@ -703,7 +703,7 @@ public: for (auto row_iter = row.rbegin(); row_iter != row.rend(); row_iter++) { const auto cell = *row_iter; - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -711,7 +711,7 @@ public: void test_column_major_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -721,10 +721,10 @@ public: auto first_column = *columns.begin(); auto first_column_iter = first_column.begin(); auto first_cell = *first_column_iter; - TS_ASSERT_EQUALS(first_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(first_cell.value(), "A1"); first_column_iter++; auto second_cell = *first_column_iter; - TS_ASSERT_EQUALS(second_cell.get_value(), "A2"); + TS_ASSERT_EQUALS(second_cell.value(), "A2"); TS_ASSERT_EQUALS(first_cell, first_column.front()); TS_ASSERT_EQUALS(second_cell, first_column.back()); @@ -733,16 +733,16 @@ public: auto last_column_iter = last_column.end(); last_column_iter--; auto last_cell = *last_column_iter; - TS_ASSERT_EQUALS(last_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(last_cell.value(), "C2"); last_column_iter--; auto penultimate_cell = *last_column_iter; - TS_ASSERT_EQUALS(penultimate_cell.get_value(), "C1"); + TS_ASSERT_EQUALS(penultimate_cell.value(), "C1"); for (auto column : columns) { for (auto cell : column) { - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -750,7 +750,7 @@ public: void test_reverse_column_major_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -762,19 +762,19 @@ public: auto first_column_iter = first_column.rbegin(); auto first_cell = *first_column_iter; - TS_ASSERT_EQUALS(first_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(first_cell.value(), "C2"); first_column_iter++; auto second_cell = *first_column_iter; - TS_ASSERT_EQUALS(second_cell.get_value(), "C1"); + TS_ASSERT_EQUALS(second_cell.value(), "C1"); auto last_column = *(--columns.rend()); auto last_column_iter = last_column.rend(); last_column_iter--; auto last_cell = *last_column_iter; - TS_ASSERT_EQUALS(last_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(last_cell.value(), "A1"); last_column_iter--; auto penultimate_cell = *last_column_iter; - TS_ASSERT_EQUALS(penultimate_cell.get_value(), "A2"); + TS_ASSERT_EQUALS(penultimate_cell.value(), "A2"); for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter) { @@ -784,7 +784,7 @@ public: { auto cell = *cell_iter; - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -792,7 +792,7 @@ public: void test_const_column_major_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -803,25 +803,25 @@ public: const auto first_column = *columns.begin(); auto first_column_iter = first_column.begin(); const auto first_cell = *first_column_iter; - TS_ASSERT_EQUALS(first_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(first_cell.value(), "A1"); first_column_iter++; const auto second_cell = *first_column_iter; - TS_ASSERT_EQUALS(second_cell.get_value(), "A2"); + TS_ASSERT_EQUALS(second_cell.value(), "A2"); const auto last_column = *(--columns.end()); auto last_column_iter = last_column.end(); last_column_iter--; const auto last_cell = *last_column_iter; - TS_ASSERT_EQUALS(last_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(last_cell.value(), "C2"); last_column_iter--; const auto penultimate_cell = *last_column_iter; - TS_ASSERT_EQUALS(penultimate_cell.get_value(), "C1"); + TS_ASSERT_EQUALS(penultimate_cell.value(), "C1"); for (const auto column : columns) { for (const auto cell : column) { - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -829,7 +829,7 @@ public: void test_const_reverse_column_major_iterators() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.append({"A1", "B1", "C1"}); ws.append({"A2", "B2", "C2"}); @@ -840,19 +840,19 @@ public: const auto first_column = *columns.crbegin(); auto first_column_iter = first_column.crbegin(); const auto first_cell = *first_column_iter; - TS_ASSERT_EQUALS(first_cell.get_value(), "C2"); + TS_ASSERT_EQUALS(first_cell.value(), "C2"); first_column_iter++; const auto second_cell = *first_column_iter; - TS_ASSERT_EQUALS(second_cell.get_value(), "C1"); + TS_ASSERT_EQUALS(second_cell.value(), "C1"); const auto last_column = *(--columns.crend()); auto last_column_iter = last_column.crend(); last_column_iter--; const auto last_cell = *last_column_iter; - TS_ASSERT_EQUALS(last_cell.get_value(), "A1"); + TS_ASSERT_EQUALS(last_cell.value(), "A1"); last_column_iter--; const auto penultimate_cell = *last_column_iter; - TS_ASSERT_EQUALS(penultimate_cell.get_value(), "A2"); + TS_ASSERT_EQUALS(penultimate_cell.value(), "A2"); for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter) { @@ -862,7 +862,7 @@ public: { const auto cell = *cell_iter; - TS_ASSERT_EQUALS(cell.get_value(), cell.get_reference().to_string()); + TS_ASSERT_EQUALS(cell.value(), cell.reference().to_string()); } } } @@ -870,20 +870,20 @@ public: void test_header() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - auto &header_footer = ws.get_header_footer(); + auto &header_footer = ws.header_footer(); - for (auto header_pointer : { &header_footer.get_left_header(), - &header_footer.get_center_header(), &header_footer.get_right_header() }) + for (auto header_pointer : { &header_footer.left_header(), + &header_footer.center_header(), &header_footer.right_header() }) { auto &header = *header_pointer; TS_ASSERT(header.is_default()); - header.set_text("abc"); - header.set_font_name("def"); - header.set_font_size(121); - header.set_font_color("ghi"); + header.text("abc"); + header.font_name("def"); + header.font_size(121); + header.font_color("ghi"); TS_ASSERT(!header.is_default()); } } @@ -891,20 +891,20 @@ public: void test_footer() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - auto &header_footer = ws.get_header_footer(); + auto &header_footer = ws.header_footer(); - for (auto header_pointer : { &header_footer.get_left_footer(), - &header_footer.get_center_footer(), &header_footer.get_right_footer() }) + for (auto header_pointer : { &header_footer.left_footer(), + &header_footer.center_footer(), &header_footer.right_footer() }) { auto &header = *header_pointer; TS_ASSERT(header.is_default()); - header.set_text("abc"); - header.set_font_name("def"); - header.set_font_size(121); - header.set_font_color("ghi"); + header.text("abc"); + header.font_name("def"); + header.font_size(121); + header.font_color("ghi"); TS_ASSERT(!header.is_default()); } } @@ -912,18 +912,18 @@ public: void test_page_setup() { xlnt::page_setup setup; - setup.set_break(xlnt::page_break::column); - TS_ASSERT_EQUALS(setup.get_break(), xlnt::page_break::column); - setup.set_scale(1.23); - TS_ASSERT_EQUALS(setup.get_scale(), 1.23); + setup.page_break(xlnt::page_break::column); + TS_ASSERT_EQUALS(setup.page_break(), xlnt::page_break::column); + setup.scale(1.23); + TS_ASSERT_EQUALS(setup.scale(), 1.23); } void test_unique_sheet_name() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - auto active_name = ws.get_title(); + auto active_name = ws.title(); auto next_name = ws.unique_sheet_name(active_name); TS_ASSERT_DIFFERS(active_name, next_name); @@ -932,21 +932,21 @@ public: void test_page_margins() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - auto margins = ws.get_page_margins(); + auto ws = wb.active_sheet(); + auto margins = ws.page_margins(); - margins.set_top(0); - margins.set_bottom(1); - margins.set_header(2); - margins.set_footer(3); - margins.set_left(4); - margins.set_right(5); + margins.top(0); + margins.bottom(1); + margins.header(2); + margins.footer(3); + margins.left(4); + margins.right(5); } void test_to_string() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto ws_string = ws.to_string(); TS_ASSERT_EQUALS(ws_string, ""); } @@ -954,12 +954,12 @@ public: void test_garbage_collect() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); auto dimensions = ws.calculate_dimension(); TS_ASSERT_EQUALS(dimensions, xlnt::range_reference("A1", "A1")); - ws.get_cell("B2").set_value("text"); + ws.cell("B2").value("text"); ws.garbage_collect(); dimensions = ws.calculate_dimension(); @@ -969,9 +969,9 @@ public: void test_has_cell() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("A3").set_value("test"); + ws.cell("A3").value("test"); TS_ASSERT(!ws.has_cell("A2")); TS_ASSERT(ws.has_cell("A3")); @@ -980,38 +980,38 @@ public: void test_get_range_by_string() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("A2").set_value(3.14); - ws.get_cell("A3").set_value(true); - ws.get_cell("B2").set_value("text"); - ws.get_cell("B3").set_value(false); + ws.cell("A2").value(3.14); + ws.cell("A3").value(true); + ws.cell("B2").value("text"); + ws.cell("B3").value(false); - auto range = ws.get_range("A2:B3"); + auto range = ws.range("A2:B3"); auto range_iter = range.begin(); auto row = *range_iter; auto row_iter = row.begin(); - TS_ASSERT_EQUALS((*row_iter).get_value(), 3.14); - TS_ASSERT_EQUALS((*row_iter).get_reference(), "A2"); + TS_ASSERT_EQUALS((*row_iter).value(), 3.14); + TS_ASSERT_EQUALS((*row_iter).reference(), "A2"); TS_ASSERT_EQUALS((*row_iter), row.front()); row_iter++; - TS_ASSERT_EQUALS((*row_iter).get_value(), "text"); - TS_ASSERT_EQUALS((*row_iter).get_reference(), "B2"); + TS_ASSERT_EQUALS((*row_iter).value(), "text"); + TS_ASSERT_EQUALS((*row_iter).reference(), "B2"); TS_ASSERT_EQUALS((*row_iter), row.back()); range_iter++; row = *range_iter; row_iter = row.begin(); - TS_ASSERT_EQUALS((*row_iter).get_value(), true); - TS_ASSERT_EQUALS((*row_iter).get_reference(), "A3"); + TS_ASSERT_EQUALS((*row_iter).value(), true); + TS_ASSERT_EQUALS((*row_iter).reference(), "A3"); range_iter = range.end(); range_iter--; row = *range_iter; row_iter = row.end(); row_iter--; - TS_ASSERT_EQUALS((*row_iter).get_value(), false); + TS_ASSERT_EQUALS((*row_iter).value(), false); } void test_operators() @@ -1026,24 +1026,24 @@ public: TS_ASSERT_DIFFERS(ws1, ws2); - ws1[xlnt::cell_reference("A2")].set_value(true); + ws1[xlnt::cell_reference("A2")].value(true); const auto ws1_const = ws1; - TS_ASSERT_EQUALS(ws1[xlnt::cell_reference("A2")].get_value(), true); - TS_ASSERT_EQUALS((*(*ws1[xlnt::range_reference("A2:A2")].begin()).begin()).get_value(), true); + TS_ASSERT_EQUALS(ws1[xlnt::cell_reference("A2")].value(), true); + TS_ASSERT_EQUALS((*(*ws1[xlnt::range_reference("A2:A2")].begin()).begin()).value(), true); ws1.create_named_range("rangey", "A2:A2"); - TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.get_range("A2:A2")); - TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.get_range("A2:A2")); - TS_ASSERT(ws1[std::string("rangey")] != ws1.get_range("A2:A3")); + TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.range("A2:A2")); + TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.range("A2:A2")); + TS_ASSERT(ws1[std::string("rangey")] != ws1.range("A2:A3")); - TS_ASSERT_EQUALS(ws1[std::string("rangey")].get_cell("A1"), ws1.get_cell("A2")); + TS_ASSERT_EQUALS(ws1[std::string("rangey")].cell("A1"), ws1.cell("A2")); } void test_reserve() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); ws.reserve(1000); //TODO: actual tests go here @@ -1052,10 +1052,10 @@ public: void test_iterate() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - ws.get_cell("B3").set_value("B3"); - ws.get_cell("C7").set_value("C7"); + ws.cell("B3").value("B3"); + ws.cell("C7").value("C7"); for (auto row : ws) { @@ -1063,7 +1063,7 @@ public: { if (cell.has_value()) { - TS_ASSERT_EQUALS(cell.get_reference().to_string(), cell.get_value()); + TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value()); } } } @@ -1076,12 +1076,12 @@ public: { if (cell.has_value()) { - TS_ASSERT_EQUALS(cell.get_reference().to_string(), cell.get_value()); + TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value()); } } } - const auto const_range = ws_const.get_range("B3:C7"); + const auto const_range = ws_const.range("B3:C7"); auto const_range_iter = const_range.cbegin(); const_range_iter++; const_range_iter--; @@ -1110,15 +1110,15 @@ public: void test_get_point_pos() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); - TS_ASSERT_EQUALS(ws.get_point_pos({0, 0}), "A1"); + TS_ASSERT_EQUALS(ws.point_pos({0, 0}), "A1"); } void test_named_range_named_cell_reference() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); + auto ws = wb.active_sheet(); TS_ASSERT_THROWS(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter); TS_ASSERT_THROWS(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter); TS_ASSERT_THROWS_NOTHING(ws.create_named_range("XFE1048576", "A2")); @@ -1128,9 +1128,9 @@ public: void test_iteration_skip_empty() { xlnt::workbook wb; - auto ws = wb.get_active_sheet(); - ws.get_cell("A1").set_value("A1"); - ws.get_cell("F6").set_value("F6"); + auto ws = wb.active_sheet(); + ws.cell("A1").value("A1"); + ws.cell("F6").value("F6"); { std::vector cells; @@ -1144,8 +1144,8 @@ public: } TS_ASSERT_EQUALS(cells.size(), 2); - TS_ASSERT_EQUALS(cells[0].get_value(), "A1"); - TS_ASSERT_EQUALS(cells[1].get_value(), "F6"); + TS_ASSERT_EQUALS(cells[0].value(), "A1"); + TS_ASSERT_EQUALS(cells[1].value(), "F6"); } const auto ws_const = ws; @@ -1162,8 +1162,8 @@ public: } TS_ASSERT_EQUALS(cells.size(), 2); - TS_ASSERT_EQUALS(cells[0].get_value(), "A1"); - TS_ASSERT_EQUALS(cells[1].get_value(), "F6"); + TS_ASSERT_EQUALS(cells[0].value(), "A1"); + TS_ASSERT_EQUALS(cells[1].value(), "F6"); } } }; diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 764b45e2..30edd8b4 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -64,12 +64,15 @@ worksheet::worksheet(const worksheet &rhs) : d_(rhs.d_) bool worksheet::has_frozen_panes() const { - return get_frozen_panes() != cell_reference("A1"); + return !d_->views_.empty() + && d_->views_.front().has_pane() + && (d_->views_.front().pane().state == pane_state::frozen + || d_->views_.front().pane().state == pane_state::frozen_split); } std::string worksheet::unique_sheet_name(const std::string &value) const { - auto names = get_workbook().get_sheet_titles(); + auto names = workbook().sheet_titles(); auto match = std::find(names.begin(), names.end(), value); std::size_t append = 0; @@ -109,20 +112,20 @@ void worksheet::create_named_range(const std::string &name, const range_referenc std::vector targets; targets.push_back({ *this, reference }); - d_->named_ranges_[name] = named_range(name, targets); + d_->named_ranges_[name] = xlnt::named_range(name, targets); } range worksheet::operator()(const xlnt::cell_reference &top_left, const xlnt::cell_reference &bottom_right) { - return get_range(range_reference(top_left, bottom_right)); + return range(range_reference(top_left, bottom_right)); } cell worksheet::operator[](const cell_reference &ref) { - return get_cell(ref); + return cell(ref); } -std::vector worksheet::get_merged_ranges() const +std::vector worksheet::merged_ranges() const { return d_->merged_cells_; } @@ -137,12 +140,12 @@ bool worksheet::has_page_setup() const return d_->has_page_setup_; } -page_margins worksheet::get_page_margins() const +page_margins worksheet::page_margins() const { return d_->page_margins_; } -void worksheet::set_page_margins(const page_margins &margins) +void worksheet::page_margins(const class page_margins &margins) { d_->page_margins_ = margins; d_->has_page_margins_ = true; @@ -160,31 +163,31 @@ void worksheet::auto_filter(const range_reference &reference) void worksheet::auto_filter(const xlnt::range &range) { - auto_filter(range.get_reference()); + auto_filter(range.reference()); } -range_reference worksheet::get_auto_filter() const +range_reference worksheet::auto_filter() const { return d_->auto_filter_; } bool worksheet::has_auto_filter() const { - return d_->auto_filter_.get_width() > 0; + return d_->auto_filter_.width() > 0; } -void worksheet::unset_auto_filter() +void worksheet::clear_auto_filter() { d_->auto_filter_ = range_reference(1, 1, 1, 1); } -void worksheet::set_page_setup(const page_setup &setup) +void worksheet::page_setup(const struct page_setup &setup) { d_->has_page_setup_ = true; d_->page_setup_ = setup; } -page_setup worksheet::get_page_setup() const +page_setup worksheet::page_setup() const { if (!d_->has_page_setup_) { @@ -199,12 +202,12 @@ std::string worksheet::to_string() const return "title_ + "\">"; } -workbook &worksheet::get_workbook() +workbook &worksheet::workbook() { return *d_->parent_; } -const workbook &worksheet::get_workbook() const +const workbook &worksheet::workbook() const { return *d_->parent_; } @@ -219,7 +222,7 @@ void worksheet::garbage_collect() while (cell_iter != cell_map_iter->second.end()) { - cell current_cell(&cell_iter->second); + class cell current_cell(&cell_iter->second); if (current_cell.garbage_collectible()) { @@ -240,22 +243,22 @@ void worksheet::garbage_collect() } } -void worksheet::set_id(std::size_t id) +void worksheet::id(std::size_t id) { d_->id_ = id; } -std::size_t worksheet::get_id() const +std::size_t worksheet::id() const { return d_->id_; } -std::string worksheet::get_title() const +std::string worksheet::title() const { return d_->title_; } -void worksheet::set_title(const std::string &title) +void worksheet::title(const std::string &title) { if (title.length() > 31) { @@ -267,119 +270,145 @@ void worksheet::set_title(const std::string &title) throw invalid_sheet_title(title); } - auto same_title = std::find_if(get_workbook().begin(), get_workbook().end(), - [&](worksheet ws) { return ws.get_title() == title; }); + auto same_title = std::find_if(workbook().begin(), workbook().end(), + [&](worksheet ws) { return ws.title() == title; }); - if (same_title != get_workbook().end() && *same_title != *this) + if (same_title != workbook().end() && *same_title != *this) { throw invalid_sheet_title(title); } - get_workbook().d_->sheet_title_rel_id_map_[title] = - get_workbook().d_->sheet_title_rel_id_map_[d_->title_]; - get_workbook().d_->sheet_title_rel_id_map_.erase(d_->title_); + workbook().d_->sheet_title_rel_id_map_[title] = + workbook().d_->sheet_title_rel_id_map_[d_->title_]; + workbook().d_->sheet_title_rel_id_map_.erase(d_->title_); d_->title_ = title; } -cell_reference worksheet::get_frozen_panes() const +cell_reference worksheet::frozen_panes() const { - return d_->view_.get_pane().top_left_cell; + if (!has_frozen_panes()) + { + throw xlnt::invalid_attribute(); + } + + return d_->views_.front().pane().top_left_cell.get(); } void worksheet::freeze_panes(xlnt::cell top_left_cell) { - freeze_panes(top_left_cell.get_reference().to_string()); + freeze_panes(top_left_cell.reference()); } -void worksheet::freeze_panes(const std::string &top_left_coordinate) +void worksheet::freeze_panes(const cell_reference &ref) { - auto ref = cell_reference(top_left_coordinate); - d_->view_.get_pane().top_left_cell = ref; - d_->view_.get_pane().state = pane_state::frozen; - - d_->view_.get_selections().clear(); - d_->view_.get_selections().push_back(selection()); - - if (ref.get_column_index() == 1 - && ref.get_row() == 1) + if (!has_view()) { - d_->view_.get_selections().back().set_pane(pane_corner::top_left); - d_->view_.get_pane().active_pane = pane_corner::top_left; - d_->view_.get_pane().state = pane_state::normal; + d_->views_.push_back(sheet_view()); } - else if (ref.get_column_index() == 1) + + auto &primary_view = d_->views_.front(); + + if (!primary_view.has_pane()) { - d_->view_.get_selections().back().set_pane(pane_corner::bottom_left); - d_->view_.get_pane().active_pane = pane_corner::bottom_left; - d_->view_.get_pane().y_split = ref.get_row() - 1; + primary_view.pane(pane()); } - else if (ref.get_row() == 1) + + primary_view.pane().top_left_cell = ref; + primary_view.pane().state = pane_state::frozen; + + primary_view.clear_selections(); + primary_view.add_selection(selection()); + + if (ref == "A1") { - d_->view_.get_selections().back().set_pane(pane_corner::top_right); - d_->view_.get_pane().active_pane = pane_corner::top_right; - d_->view_.get_pane().x_split = ref.get_column_index().index - 1; + unfreeze_panes(); + } + else if (ref.column() == "A") + { + primary_view.add_selection(selection()); + primary_view.selection(0).pane(pane_corner::bottom_left); + primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above + primary_view.selection(1).active_cell(ref); + primary_view.pane().active_pane = pane_corner::bottom_left; + primary_view.pane().y_split = ref.row() - 1; + } + else if (ref.row() == 1) + { + primary_view.add_selection(selection()); + primary_view.selection(0).pane(pane_corner::top_right); + primary_view.selection(0).active_cell(ref.make_offset(-1, 0)); // cell to the left + primary_view.selection(1).active_cell(ref); + primary_view.pane().active_pane = pane_corner::top_right; + primary_view.pane().x_split = ref.column_index() - 1; } else { - d_->view_.get_selections().push_back(selection()); - d_->view_.get_selections().push_back(selection()); - d_->view_.get_selections()[0].set_pane(pane_corner::top_right); - d_->view_.get_selections()[1].set_pane(pane_corner::bottom_left); - d_->view_.get_selections()[2].set_pane(pane_corner::bottom_right); - d_->view_.get_pane().active_pane = pane_corner::bottom_right; - d_->view_.get_pane().x_split = ref.get_column_index().index - 1; - d_->view_.get_pane().y_split = ref.get_row() - 1; + primary_view.add_selection(selection()); + primary_view.add_selection(selection()); + primary_view.selection(0).pane(pane_corner::top_right); + primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above + primary_view.selection(1).pane(pane_corner::bottom_left); + primary_view.selection(1).active_cell(ref.make_offset(-1, 0)); // cell to the left + primary_view.selection(2).pane(pane_corner::bottom_right); + primary_view.selection(2).active_cell(ref); + primary_view.pane().active_pane = pane_corner::bottom_right; + primary_view.pane().x_split = ref.column_index() - 1; + primary_view.pane().y_split = ref.row() - 1; } } void worksheet::unfreeze_panes() { - d_->view_.get_pane().top_left_cell = cell_reference("A1"); - d_->view_.get_pane().state = pane_state::normal; + if (!has_view()) return; + + auto &primary_view = d_->views_.front(); + + primary_view.clear_selections(); + primary_view.clear_pane(); } -cell worksheet::get_cell(column_t column, row_t row) +cell worksheet::cell(column_t column, row_t row) { - return get_cell(cell_reference(column, row)); + return cell(cell_reference(column, row)); } -const cell worksheet::get_cell(column_t column, row_t row) const +const cell worksheet::cell(column_t column, row_t row) const { - return get_cell(cell_reference(column, row)); + return cell(cell_reference(column, row)); } -cell worksheet::get_cell(const cell_reference &reference) +cell worksheet::cell(const cell_reference &reference) { - if (d_->cell_map_.find(reference.get_row()) == d_->cell_map_.end()) + if (d_->cell_map_.find(reference.row()) == d_->cell_map_.end()) { - d_->cell_map_[reference.get_row()] = std::unordered_map(); + d_->cell_map_[reference.row()] = std::unordered_map(); } - auto &row = d_->cell_map_[reference.get_row()]; + auto &row = d_->cell_map_[reference.row()]; - if (row.find(reference.get_column_index()) == row.end()) + if (row.find(reference.column_index()) == row.end()) { - auto &impl = row[reference.get_column_index()] = detail::cell_impl(); + auto &impl = row[reference.column_index()] = detail::cell_impl(); impl.parent_ = d_; - impl.column_ = reference.get_column_index(); - impl.row_ = reference.get_row(); + impl.column_ = reference.column_index(); + impl.row_ = reference.row(); } - return cell(&row[reference.get_column_index()]); + return xlnt::cell(&row[reference.column_index()]); } -const cell worksheet::get_cell(const cell_reference &reference) const +const cell worksheet::cell(const cell_reference &reference) const { - return cell(&d_->cell_map_.at(reference.get_row()).at(reference.get_column_index())); + return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index())); } bool worksheet::has_cell(const cell_reference &reference) const { - const auto row = d_->cell_map_.find(reference.get_row()); + const auto row = d_->cell_map_.find(reference.row()); if(row == d_->cell_map_.cend()) return false; - const auto col = row->second.find(reference.get_column_index()); + const auto col = row->second.find(reference.column_index()); if(col == row->second.cend()) return false; @@ -391,9 +420,9 @@ bool worksheet::has_row_properties(row_t row) const return d_->row_properties_.find(row) != d_->row_properties_.end(); } -range worksheet::get_named_range(const std::string &name) +range worksheet::named_range(const std::string &name) { - if (!get_workbook().has_named_range(name)) + if (!workbook().has_named_range(name)) { throw key_not_found(); } @@ -403,10 +432,10 @@ range worksheet::get_named_range(const std::string &name) throw key_not_found(); } - return get_range(d_->named_ranges_[name].get_targets()[0].second); + return range(d_->named_ranges_[name].targets()[0].second); } -column_t worksheet::get_lowest_column() const +column_t worksheet::lowest_column() const { if (d_->cell_map_.empty()) { @@ -426,7 +455,7 @@ column_t worksheet::get_lowest_column() const return lowest; } -row_t worksheet::get_lowest_row() const +row_t worksheet::lowest_row() const { if (d_->cell_map_.empty()) { @@ -443,7 +472,7 @@ row_t worksheet::get_lowest_row() const return lowest; } -row_t worksheet::get_highest_row() const +row_t worksheet::highest_row() const { row_t highest = constants::min_row(); @@ -455,7 +484,7 @@ row_t worksheet::get_highest_row() const return highest; } -column_t worksheet::get_highest_column() const +column_t worksheet::highest_column() const { column_t highest = constants::min_column(); @@ -482,33 +511,27 @@ bool worksheet::has_format_properties() const range_reference worksheet::calculate_dimension() const { - auto lowest_column = get_lowest_column(); - auto lowest_row = get_lowest_row(); - - auto highest_column = get_highest_column(); - auto highest_row = get_highest_row(); - - return range_reference(lowest_column, lowest_row, highest_column, highest_row); + return range_reference(lowest_column(), lowest_row(), highest_column(), highest_row()); } -range worksheet::get_range(const std::string &reference_string) +range worksheet::range(const std::string &reference_string) { - return get_range(range_reference(reference_string)); + return range(range_reference(reference_string)); } -range worksheet::get_range(const range_reference &reference) +range worksheet::range(const range_reference &reference) { - return range(*this, reference); + return xlnt::range(*this, reference); } -const range worksheet::get_range(const std::string &reference_string) const +const range worksheet::range(const std::string &reference_string) const { - return get_range(range_reference(reference_string)); + return range(range_reference(reference_string)); } -const range worksheet::get_range(const range_reference &reference) const +const range worksheet::range(const range_reference &reference) const { - return range(*this, reference); + return xlnt::range(*this, reference); } void worksheet::merge_cells(const std::string &reference_string) @@ -526,17 +549,17 @@ void worksheet::merge_cells(const range_reference &reference) d_->merged_cells_.push_back(reference); bool first = true; - for (auto row : get_range(reference)) + for (auto row : range(reference)) { for (auto cell : row) { - cell.set_merged(true); + cell.merged(true); if (!first) { - if (cell.get_data_type() == cell::type::string) + if (cell.data_type() == cell::type::string) { - cell.set_value(""); + cell.value(""); } else { @@ -565,11 +588,11 @@ void worksheet::unmerge_cells(const range_reference &reference) d_->merged_cells_.erase(match); - for (auto row : get_range(reference)) + for (auto row : range(reference)) { for (auto cell : row) { - cell.set_merged(false); + cell.merged(false); } } } @@ -581,23 +604,23 @@ void worksheet::unmerge_cells(column_t start_column, row_t start_row, column_t e void worksheet::append() { - get_cell(cell_reference(1, get_next_row())); + cell(cell_reference(1, next_row())); } void worksheet::append(const std::vector &cells) { - xlnt::cell_reference next(1, get_next_row()); + xlnt::cell_reference next(1, next_row()); for (auto cell : cells) { - get_cell(next).set_value(cell); - next.set_column_index(next.get_column_index() + 1); + this->cell(next).value(cell); + next.column_index(next.column_index() + 1); } } -row_t worksheet::get_next_row() const +row_t worksheet::next_row() const { - auto row = get_highest_row() + 1; + auto row = highest_row() + 1; if (row == 2 && d_->cell_map_.size() == 0) { @@ -609,71 +632,71 @@ row_t worksheet::get_next_row() const void worksheet::append(const std::vector &cells) { - xlnt::cell_reference next(1, get_next_row()); + xlnt::cell_reference next(1, next_row()); for (auto cell : cells) { - get_cell(next).set_value(cell); - next.set_column_index(next.get_column_index() + 1); + this->cell(next).value(cell); + next.column_index(next.column_index() + 1); } } void worksheet::append(const std::unordered_map &cells) { - auto row = get_next_row(); + auto row = next_row(); for (auto cell : cells) { - get_cell(cell_reference(cell.first, row)).set_value(cell.second); + this->cell(cell_reference(cell.first, row)).value(cell.second); } } void worksheet::append(const std::unordered_map &cells) { - auto row = get_next_row(); + auto row = next_row(); for (auto cell : cells) { - get_cell(cell_reference(static_cast(cell.first), row)).set_value(cell.second); + this->cell(cell_reference(static_cast(cell.first), row)).value(cell.second); } } void worksheet::append(const std::vector::const_iterator begin, const std::vector::const_iterator end) { - xlnt::cell_reference next(1, get_next_row()); + xlnt::cell_reference next(1, next_row()); for (auto i = begin; i != end; i++) { - get_cell(next).set_value(*i); - next.set_column_index(next.get_column_index() + 1); + cell(next).value(*i); + next.column_index(next.column_index() + 1); } } xlnt::range worksheet::rows() const { - return get_range(calculate_dimension()); + return range(calculate_dimension()); } xlnt::range worksheet::rows(const std::string &range_string) const { - return get_range(range_reference(range_string)); + return range(range_reference(range_string)); } xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int column_offset) const { range_reference reference(range_string); - return get_range(reference.make_offset(column_offset, row_offset)); + return range(reference.make_offset(column_offset, row_offset)); } xlnt::range worksheet::rows(int row_offset, int column_offset) const { range_reference reference(calculate_dimension()); - return get_range(reference.make_offset(column_offset, row_offset)); + return range(reference.make_offset(column_offset, row_offset)); } xlnt::range worksheet::columns() const { - return range(*this, calculate_dimension(), major_order::column); + return xlnt::range(*this, calculate_dimension(), major_order::column); } bool worksheet::operator==(const worksheet &other) const @@ -707,13 +730,13 @@ bool worksheet::compare(const worksheet &other, bool reference) const xlnt::cell this_cell(&cell.second); xlnt::cell other_cell(&other.d_->cell_map_[row.first][cell.first]); - if (this_cell.get_data_type() != other_cell.get_data_type()) + if (this_cell.data_type() != other_cell.data_type()) { return false; } - if (this_cell.get_data_type() == xlnt::cell::type::numeric - && std::fabs(this_cell.get_value() - other_cell.get_value()) > 0.L) + if (this_cell.data_type() == xlnt::cell::type::numeric + && std::fabs(this_cell.value() - other_cell.value()) > 0.L) { return false; } @@ -724,7 +747,7 @@ bool worksheet::compare(const worksheet &other, bool reference) const if(d_->auto_filter_ == other.d_->auto_filter_ && d_->comment_count_ == other.d_->comment_count_ - && d_->view_.get_pane().top_left_cell == other.d_->view_.get_pane().top_left_cell + && d_->views_ == other.d_->views_ && d_->merged_cells_ == other.d_->merged_cells_ && d_->relationships_ == other.d_->relationships_) { @@ -756,21 +779,21 @@ void worksheet::operator=(const worksheet &other) const cell worksheet::operator[](const cell_reference &ref) const { - return get_cell(ref); + return cell(ref); } range worksheet::operator[](const range_reference &ref) { - return get_range(ref); + return range(ref); } range worksheet::operator[](const std::string &name) { if (has_named_range(name)) { - return get_named_range(name); + return named_range(name); } - return get_range(range_reference(name)); + return range(range_reference(name)); } bool worksheet::has_named_range(const std::string &name) @@ -803,17 +826,17 @@ void worksheet::decrement_comments() d_->comment_count_--; } -std::size_t worksheet::get_comment_count() const +std::size_t worksheet::comment_count() const { return d_->comment_count_; } -header_footer &worksheet::get_header_footer() +header_footer &worksheet::header_footer() { return d_->header_footer_; } -const header_footer &worksheet::get_header_footer() const +const header_footer &worksheet::header_footer() const { return d_->header_footer_; } @@ -830,17 +853,17 @@ footer::footer() : default_(true), font_size_(12) { } -void worksheet::set_parent(xlnt::workbook &wb) +void worksheet::parent(xlnt::workbook &wb) { d_->parent_ = &wb; } -std::vector worksheet::get_formula_attributes() const +std::vector worksheet::formula_attributes() const { return {}; } -cell_reference worksheet::get_point_pos(int left, int top) const +cell_reference worksheet::point_pos(int left, int top) const { static const auto DefaultColumnWidth = 51.85L; static const auto DefaultRowHeight = 15.0L; @@ -865,7 +888,7 @@ cell_reference worksheet::get_point_pos(int left, int top) const if (has_column_properties(current_column)) { - auto cdw = get_column_properties(current_column).width; + auto cdw = column_properties(current_column).width; if (cdw >= 0) { @@ -883,7 +906,7 @@ cell_reference worksheet::get_point_pos(int left, int top) const if (has_row_properties(current_row)) { - auto cdh = get_row_properties(current_row).height; + auto cdh = row_properties(current_row).height; if (cdh >= 0) { @@ -898,19 +921,19 @@ cell_reference worksheet::get_point_pos(int left, int top) const return { current_column - 1, current_row - 1 }; } -cell_reference worksheet::get_point_pos(const std::pair &point) const +cell_reference worksheet::point_pos(const std::pair &point) const { - return get_point_pos(point.first, point.second); + return point_pos(point.first, point.second); } -void worksheet::set_sheet_state(sheet_state state) +void worksheet::sheet_state(enum sheet_state state) { - get_page_setup().set_sheet_state(state); + page_setup().sheet_state(state); } -sheet_state worksheet::get_sheet_state() const +sheet_state worksheet::sheet_state() const { - return get_page_setup().get_sheet_state(); + return page_setup().sheet_state(); } void worksheet::add_column_properties(column_t column, const xlnt::column_properties &props) @@ -923,22 +946,22 @@ bool worksheet::has_column_properties(column_t column) const return d_->column_properties_.find(column) != d_->column_properties_.end(); } -column_properties &worksheet::get_column_properties(column_t column) +column_properties &worksheet::column_properties(column_t column) { return d_->column_properties_[column]; } -const column_properties &worksheet::get_column_properties(column_t column) const +const column_properties &worksheet::column_properties(column_t column) const { return d_->column_properties_.at(column); } -row_properties &worksheet::get_row_properties(row_t row) +row_properties &worksheet::row_properties(row_t row) { return d_->row_properties_[row]; } -const row_properties &worksheet::get_row_properties(row_t row) const +const row_properties &worksheet::row_properties(row_t row) const { return d_->row_properties_.at(row); } @@ -946,8 +969,8 @@ const row_properties &worksheet::get_row_properties(row_t row) const worksheet::iterator worksheet::begin() { auto dimensions = calculate_dimension(); - cell_reference top_right(dimensions.get_bottom_right().get_column_index(), dimensions.get_top_left().get_row()); - range_reference row_range(dimensions.get_top_left(), top_right); + cell_reference top_right(dimensions.bottom_right().column_index(), dimensions.top_left().row()); + range_reference row_range(dimensions.top_left(), top_right); return iterator(*this, row_range, dimensions, major_order::row); } @@ -955,9 +978,9 @@ worksheet::iterator worksheet::begin() worksheet::iterator worksheet::end() { auto dimensions = calculate_dimension(); - auto past_end_row_index = dimensions.get_bottom_right().get_row() + 1; - cell_reference bottom_left(dimensions.get_top_left().get_column_index(), past_end_row_index); - cell_reference bottom_right(dimensions.get_bottom_right().get_column_index(), past_end_row_index); + auto past_end_row_index = dimensions.bottom_right().row() + 1; + cell_reference bottom_left(dimensions.top_left().column_index(), past_end_row_index); + cell_reference bottom_right(dimensions.bottom_right().column_index(), past_end_row_index); return iterator(*this, range_reference(bottom_left, bottom_right), dimensions, major_order::row); } @@ -965,8 +988,8 @@ worksheet::iterator worksheet::end() worksheet::const_iterator worksheet::cbegin() const { auto dimensions = calculate_dimension(); - cell_reference top_right(dimensions.get_bottom_right().get_column_index(), dimensions.get_top_left().get_row()); - range_reference row_range(dimensions.get_top_left(), top_right); + cell_reference top_right(dimensions.bottom_right().column_index(), dimensions.top_left().row()); + range_reference row_range(dimensions.top_left(), top_right); return const_iterator(*this, row_range, major_order::row); } @@ -974,9 +997,9 @@ worksheet::const_iterator worksheet::cbegin() const worksheet::const_iterator worksheet::cend() const { auto dimensions = calculate_dimension(); - auto past_end_row_index = dimensions.get_bottom_right().get_row() + 1; - cell_reference bottom_left(dimensions.get_top_left().get_column_index(), past_end_row_index); - cell_reference bottom_right(dimensions.get_bottom_right().get_column_index(), past_end_row_index); + auto past_end_row_index = dimensions.bottom_right().row() + 1; + cell_reference bottom_left(dimensions.top_left().column_index(), past_end_row_index); + cell_reference bottom_right(dimensions.bottom_right().column_index(), past_end_row_index); return const_iterator(*this, range_reference(bottom_left, bottom_right), major_order::row); } @@ -993,30 +1016,30 @@ worksheet::const_iterator worksheet::end() const range worksheet::iter_cells(bool skip_null) { - return range(*this, calculate_dimension(), major_order::row, skip_null); + return xlnt::range(*this, calculate_dimension(), major_order::row, skip_null); } -void worksheet::set_print_title_rows(row_t last_row) +void worksheet::print_title_rows(row_t last_row) { - set_print_title_rows(1, last_row); + print_title_rows(1, last_row); } -void worksheet::set_print_title_rows(row_t first_row, row_t last_row) +void worksheet::print_title_rows(row_t first_row, row_t last_row) { d_->print_title_rows_ = std::to_string(first_row) + ":" + std::to_string(last_row); } -void worksheet::set_print_title_cols(column_t last_column) +void worksheet::print_title_cols(column_t last_column) { - set_print_title_cols(1, last_column); + print_title_cols(1, last_column); } -void worksheet::set_print_title_cols(column_t first_column, column_t last_column) +void worksheet::print_title_cols(column_t first_column, column_t last_column) { d_->print_title_cols_ = first_column.column_string() + ":" + last_column.column_string(); } -std::string worksheet::get_print_titles() const +std::string worksheet::print_titles() const { if (!d_->print_title_rows_.empty() && !d_->print_title_cols_.empty()) { @@ -1032,44 +1055,34 @@ std::string worksheet::get_print_titles() const } } -void worksheet::set_print_area(const std::string &print_area) +void worksheet::print_area(const std::string &print_area) { d_->print_area_ = range_reference::make_absolute(range_reference(print_area)); } -range_reference worksheet::get_print_area() const +range_reference worksheet::print_area() const { return d_->print_area_; } bool worksheet::has_view() const { - return d_->has_view_; + return !d_->views_.empty(); } -sheet_view worksheet::get_view() const +sheet_view worksheet::view(std::size_t index) const { - return d_->view_; + return d_->views_.at(index); } -bool worksheet::x14ac_enabled() const +void worksheet::add_view(const sheet_view &new_view) { - return d_->x14ac_; -} - -void worksheet::enable_x14ac() -{ - d_->x14ac_ = true; -} - -void worksheet::disable_x14ac() -{ - d_->x14ac_ = false; + d_->views_.push_back(new_view); } void worksheet::register_comments_in_manifest() { - get_workbook().register_comments_in_manifest(*this); + workbook().register_comments_in_manifest(*this); } } // namespace xlnt diff --git a/tests/helpers/xml_helper.hpp b/tests/helpers/xml_helper.hpp index 91fbcc2e..3d6c84dd 100644 --- a/tests/helpers/xml_helper.hpp +++ b/tests/helpers/xml_helper.hpp @@ -368,14 +368,14 @@ public: bool match = true; - xlnt::workbook right_workbook; - right_workbook.load(right); - xlnt::workbook left_workbook; left_workbook.load(left); + + xlnt::workbook right_workbook; + right_workbook.load(right); - auto &left_manifest = left_workbook.get_manifest(); - auto &right_manifest = right_workbook.get_manifest(); + auto &left_manifest = left_workbook.manifest(); + auto &right_manifest = right_workbook.manifest(); for (auto left_member : left_info) { @@ -404,8 +404,8 @@ public: if (left_member != "[Content_Types].xml") { - left_content_type = left_manifest.get_content_type(xlnt::path(left_member)); - right_content_type = right_manifest.get_content_type(xlnt::path(left_member)); + left_content_type = left_manifest.content_type(xlnt::path(left_member)); + right_content_type = right_manifest.content_type(xlnt::path(left_member)); } else {