diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 1fdf7dc1..09ee5905 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -34,8 +34,6 @@ #include #include -namespace CxxTest { class TestSuite; } - namespace xlnt { class alignment; @@ -66,8 +64,6 @@ class worksheet; class worksheet_iterator; class zip_file; -enum class encoding; - namespace detail { struct workbook_impl; } // namespace detail @@ -82,21 +78,35 @@ public: using const_iterator = const_worksheet_iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - - static std::size_t index_from_ws_filename(const std::string &filename); - - // constructors - workbook(); - - workbook &operator=(workbook other); - workbook(workbook &&other); - workbook(const workbook &other); - - ~workbook(); + /// + /// Swap the data held in workbooks "left" and "right". + /// friend void swap(workbook &left, workbook &right); - worksheet get_active_sheet(); + // constructors + + /// + /// Create a workbook containing a single empty worksheet. + /// + workbook(); + + /// + /// Move construct this workbook from existing workbook "other". + /// + workbook(workbook &&other); + + /// + /// Copy construct this workbook from existing workbook "other". + /// + workbook(const workbook &other); + + /// + /// Destroy this workbook. + /// + ~workbook(); + + // general properties bool get_guess_types() const; void set_guess_types(bool guess); @@ -107,31 +117,67 @@ public: bool get_read_only() const; void set_read_only(bool read_only); - // create + // add worksheets + worksheet create_sheet(); worksheet create_sheet(std::size_t index); worksheet create_sheet(const std::string &title); worksheet create_sheet(std::size_t index, const std::string &title); worksheet create_sheet(const std::string &title, const relationship &rel); - // add - void add_sheet(worksheet worksheet); - void add_sheet(worksheet worksheet, std::size_t index); + void copy_sheet(worksheet worksheet); + void copy_sheet(worksheet worksheet, std::size_t index); + + // get worksheets + + /// + /// Returns the worksheet that was most recently accessed. + /// This is also the sheet that will be shown when the workbook is opened + /// in the spreadsheet editor program. + /// + worksheet get_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_name(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_name(const std::string &sheet_name) const; + + /// + /// Return the worksheet at the given index. + /// + worksheet get_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; + + /// + /// Return true if this workbook contains a sheet with the given name. + /// + bool contains(const std::string &key) const; + + /// + /// Return the index of the given worksheet. + /// The worksheet must be owned by this workbook. + /// + std::size_t get_index(worksheet worksheet); + + // remove worksheets - // remove void remove_sheet(worksheet worksheet); void clear(); - // container operations - worksheet get_sheet_by_name(const std::string &sheet_name); - const worksheet get_sheet_by_name(const std::string &sheet_name) const; - worksheet get_sheet_by_index(std::size_t index); - const worksheet get_sheet_by_index(std::size_t index) const; - bool contains(const std::string &key) const; - int get_index(worksheet worksheet); - - worksheet operator[](const std::string &name); - worksheet operator[](std::size_t index); + // iterators iterator begin(); iterator end(); @@ -160,6 +206,7 @@ public: const app_properties &get_app_properties() const; // named ranges + std::vector get_named_ranges() const; void create_named_range(const std::string &name, worksheet worksheet, const range_reference &reference); void create_named_range(const std::string &name, worksheet worksheet, const std::string &reference_string); @@ -168,6 +215,7 @@ public: void remove_named_range(const std::string &name); // serialization + bool save(std::vector &data); bool save(const std::string &filename); bool load(const std::vector &data); @@ -175,28 +223,14 @@ public: bool load(std::istream &stream); bool load(zip_file &archive); - bool operator==(const workbook &rhs) const; - - bool operator!=(const workbook &rhs) const - { - return !(*this == rhs); - } - - bool operator==(std::nullptr_t) const; - - bool operator!=(std::nullptr_t) const - { - return !(*this == std::nullptr_t{}); - } - - void create_relationship(const std::string &id, const std::string &target, relationship::type type); - relationship get_relationship(const std::string &id) const; - const std::vector &get_relationships() const; - void set_code_name(const std::string &code_name); + // theme + bool has_loaded_theme() const; const theme &get_loaded_theme() const; + + // formats format &get_format(std::size_t format_index); const format &get_format(std::size_t format_index) const; @@ -204,8 +238,9 @@ public: void clear_formats(); std::vector &get_formats(); const std::vector &get_formats() const; - - // Named Styles + + // named styles + bool has_style(const std::string &name) const; style &get_style(const std::string &name); const style &get_style(const std::string &name) const; @@ -217,26 +252,83 @@ public: void clear_styles(); const std::vector