diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp index 82ddf70d..f81e9081 100644 --- a/include/xlnt/cell/cell.hpp +++ b/include/xlnt/cell/cell.hpp @@ -32,6 +32,8 @@ namespace xlnt { +enum class calendar; + class cell_reference; class comment; class relationship; @@ -107,28 +109,22 @@ public: bool has_hyperlink() const; // style - bool has_style() const; - style &get_style(); - const style &get_style() const; - void set_style(const style &s); - - // style shortcuts - std::string get_number_format(); - std::string get_number_format() const; - void set_number_format(const std::string &format_code, int index = -1); - font &get_font(); + std::size_t get_style_id() const; + const number_format &get_number_format() const; + void set_number_format(const number_format &format); const font &get_font() const; - fill &get_fill(); + void set_font(const font &font_); const fill &get_fill() const; - border &get_border(); + void set_fill(const fill &fill_); const border &get_border() const; - alignment &get_alignment(); + void set_border(const border &border_); const alignment &get_alignment() const; - protection &get_protection(); + void set_alignment(const alignment &alignment_); const protection &get_protection() const; - bool pivot_button(); + void set_protection(const protection &protection_); + void set_pivot_button(bool b); bool pivot_button() const; - bool quote_prefix(); + void set_quote_prefix(bool b); bool quote_prefix() const; // comment @@ -168,6 +164,8 @@ public: worksheet get_parent(); const worksheet get_parent() const; + calendar get_base_date() const; + // operators cell &operator=(const cell &rhs); @@ -178,8 +176,10 @@ public: friend bool operator<(cell left, cell right); private: - void set_value_guess_type(const std::string &s); friend class worksheet; + friend struct detail::cell_impl; + friend class style; + cell(detail::cell_impl *d); detail::cell_impl *d_; }; diff --git a/include/xlnt/common/datetime.hpp b/include/xlnt/common/datetime.hpp index c0296f8f..6918ce8a 100644 --- a/include/xlnt/common/datetime.hpp +++ b/include/xlnt/common/datetime.hpp @@ -152,6 +152,8 @@ struct datetime /// struct timedelta { + static timedelta from_number(long double number); + timedelta(int days_, int hours_, int minutes_ = 0, int seconds_ = 0, int microseconds_ = 0) : days(days_), hours(hours_), diff --git a/include/xlnt/reader/workbook_reader.hpp b/include/xlnt/reader/workbook_reader.hpp index 2cfb162c..cbe96032 100644 --- a/include/xlnt/reader/workbook_reader.hpp +++ b/include/xlnt/reader/workbook_reader.hpp @@ -31,5 +31,6 @@ namespace xlnt { class workbook; xlnt::workbook load_workbook(const std::vector &bytes); +xlnt::workbook load_workbook(const std::string &filename); } // namespace xlnt diff --git a/include/xlnt/styles/alignment.hpp b/include/xlnt/styles/alignment.hpp index 161d0063..7dd5e64b 100644 --- a/include/xlnt/styles/alignment.hpp +++ b/include/xlnt/styles/alignment.hpp @@ -64,6 +64,8 @@ public: && indent_ == other.indent_; } + std::size_t hash() const { return 0; } + private: horizontal_alignment horizontal_ = horizontal_alignment::general; vertical_alignment vertical_ = vertical_alignment::bottom; diff --git a/include/xlnt/styles/borders.hpp b/include/xlnt/styles/borders.hpp index 5f5692e5..a65f3055 100644 --- a/include/xlnt/styles/borders.hpp +++ b/include/xlnt/styles/borders.hpp @@ -23,6 +23,8 @@ // @author: see AUTHORS file #pragma once +#include + #include namespace xlnt { @@ -103,6 +105,8 @@ public: && diagonal_up == other.diagonal_up && diagonal_down == other.diagonal_down; } + + std::size_t hash() const { return 0; } }; } // namespace xlnt diff --git a/include/xlnt/styles/fill.hpp b/include/xlnt/styles/fill.hpp index 9ff28c67..12dc4234 100644 --- a/include/xlnt/styles/fill.hpp +++ b/include/xlnt/styles/fill.hpp @@ -60,10 +60,12 @@ public: color start_color = color::white; color end_color = color::black; - bool operator==(const fill &other) const + virtual bool operator==(const fill &other) const { return type_ == other.type_; } + + virtual std::size_t hash() const { return 0; } }; class pattern_fill : public fill @@ -72,6 +74,8 @@ public: void set_pattern_type(const std::string &type) { type_ = type; } void set_foreground_color(const std::string &hex) { foreground_color_ = hex; } + std::size_t hash() const override { return 0; } + private: std::string type_; std::string foreground_color_; diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index b0a49329..41b57626 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -28,6 +28,8 @@ #include namespace xlnt { + +class style; class font { @@ -56,7 +58,15 @@ public: && color_ == other.color_; } + int get_size() const { return size_; } + std::string get_name() const { return name_; } + bool is_bold() const { return bole_; } + + std::size_t hash() const { return 0; } + private: + friend class style; + std::string name_ = "Calibri"; int size_ = 11; bool bold_ = false; diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp index dde0e70c..9f8658d0 100644 --- a/include/xlnt/styles/number_format.hpp +++ b/include/xlnt/styles/number_format.hpp @@ -86,55 +86,27 @@ public: static std::string builtin_format_code(int index); static format lookup_format(int code); - static bool is_date_format(const std::string &format); static bool is_builtin(const std::string &format); - number_format() : format_code_(format::general), format_index_(0) {} - number_format(format code) : format_code_(code), format_index_(reversed_builtin_formats().at(format_strings().at(code))) {} + number_format(); + number_format(format code); + number_format(const std::string &code); - format get_format_code() const { return format_code_; } + format get_format_code() const; - void set_format_code(format format_code, int index = -1) - { - format_code_ = format_code; - - if(format_code_ != format::unknown) - { - set_format_code_string(format_strings().at(format_code), index); - } - } + void set_format_code(format format_code); - void set_format_code_string(const std::string &format_code, int index) - { - custom_format_code_ = format_code; - format_index_ = index; - - const auto &reversed = reversed_builtin_formats(); - auto match = reversed.find(format_code); - - format_code_ = format::unknown; - - if(match != reversed.end()) - { - format_index_ = match->second; - - for(const auto &p : format_strings()) - { - if(p.second == format_code) - { - format_code_ = p.first; - break; - } - } - } - - } - std::string get_format_code_string() const; + void set_format_string(const std::string &format_code); + std::string get_format_string() const; + + int get_format_index() const { return format_index_; } + + std::size_t hash() const; private: - std::string custom_format_code_ = ""; - format format_code_ = format::general; - int format_index_ = 0; + format format_code_; + int format_index_; + std::string format_string_; }; } // namespace xlnt diff --git a/include/xlnt/styles/protection.hpp b/include/xlnt/styles/protection.hpp index ed15482c..e8f23bf7 100644 --- a/include/xlnt/styles/protection.hpp +++ b/include/xlnt/styles/protection.hpp @@ -23,6 +23,8 @@ // @author: see AUTHORS file #pragma once +#include + namespace xlnt { class protection @@ -48,6 +50,8 @@ public: return locked_ == other.locked_ && hidden_ == other.hidden_; } + std::size_t hash() const { return 0; } + private: type locked_; type hidden_; diff --git a/include/xlnt/styles/style.hpp b/include/xlnt/styles/style.hpp index 4d079898..1df36535 100644 --- a/include/xlnt/styles/style.hpp +++ b/include/xlnt/styles/style.hpp @@ -23,64 +23,55 @@ // @author: see AUTHORS file #pragma once -#include "font.hpp" -#include "fill.hpp" -#include "borders.hpp" -#include "alignment.hpp" -#include "color.hpp" -#include "number_format.hpp" -#include "protection.hpp" - namespace xlnt { +namespace detail { + +struct cell_impl; + +} // namespace detail + +class alignment; +class border; +class font; +class fill; +class number_format; +class protection; + +class cell; class style { public: - style(bool is_static = false) : static_(is_static) {} + const style default_style(); + + style(); style(const style &rhs); + style &operator=(const style &rhs); style copy() const; - font &get_font(); + std::size_t hash() const; + const font &get_font() const; - void set_font(font font); - - fill &get_fill(); const fill &get_fill() const; - void set_fill(fill &fill); - - border &get_border(); const border &get_border() const; - void set_border(border borders); - - alignment &get_alignment(); - const alignment get_alignment() const; - void set_alignment(alignment alignment); - - number_format &get_number_format() { return number_format_; } - const number_format &get_number_format() const { return number_format_; } - void set_number_format(number_format number_format); - - protection &get_protection(); + const alignment &get_alignment() const; + const number_format &get_number_format() const; const protection &get_protection() const; - void set_protection(protection protection); - - bool pivot_button(); - void set_pivot_button(bool pivot); - - bool quote_prefix(); - void set_quote_prefix(bool quote); + bool pivot_button() const; + bool quote_prefix() const; private: - bool static_ = false; - font font_; - fill fill_; - border border_; - alignment alignment_; - number_format number_format_; - protection protection_; - bool pivot_button_; - bool quote_prefix_; + cell get_parent(); + const cell get_parent() const; + detail::cell_impl *parent_; + std::size_t font_id_; + std::size_t fill_id_; + std::size_t border_id_; + std::size_t alignment_id_; + std::size_t number_format_id_; + std::size_t protection_id_; + std::size_t style_id_; }; } // namespace xlnt diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 08b278a0..75bde206 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -41,11 +41,13 @@ class drawing; class fill; class font; class named_range; +class number_format; class pattern_fill; class protection; class range; class range_reference; class relationship; +class style; class worksheet; class zip_file; @@ -206,11 +208,36 @@ public: void add_color(color c); void add_number_format(const std::string &format); + const std::unordered_map &get_alignments() const; + const std::unordered_map &get_borders() const; + const std::unordered_map &get_fills() const; + const std::unordered_map &get_fonts() const; + const std::unordered_map &get_number_formats() const; + const std::unordered_map &get_protections() const; + + const number_format &get_number_format(std::size_t style_id) const; + std::size_t set_number_format(const number_format &format, std::size_t style_id); + const font &get_font(std::size_t style_id) const; + std::size_t set_font(const font &font_, std::size_t style_id); + const fill &get_fill(std::size_t style_id) const; + std::size_t set_fill(const fill &fill_, std::size_t style_id); + const border &get_border(std::size_t style_id) const; + std::size_t set_border(const border &border_, std::size_t style_id); + const alignment &get_alignment(std::size_t style_id) const; + std::size_t set_alignment(const alignment &alignment_, std::size_t style_id); + const protection &get_protection(std::size_t style_id) const; + std::size_t set_protection(const protection &protection_, std::size_t style_id); + bool get_pivot_button(std::size_t style_id) const; + bool get_quote_prefix(std::size_t style_id) const; + void set_code_name(const std::string &code_name); bool has_loaded_theme(); std::string get_loaded_theme(); + style get_style(std::size_t style_id); + std::size_t add_style(style style_); + private: friend class worksheet; std::shared_ptr d_; diff --git a/include/xlnt/writer/style_writer.hpp b/include/xlnt/writer/style_writer.hpp index abd551b4..864f6f05 100644 --- a/include/xlnt/writer/style_writer.hpp +++ b/include/xlnt/writer/style_writer.hpp @@ -39,10 +39,8 @@ public: style_writer(workbook &wb); style_writer(const style_writer &); style_writer &operator=(const style_writer &); - std::unordered_map get_style_by_hash() const; - std::string write_table() const; - std::vector