// Copyright (c) 2014-2016 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include #include #include #include #include #include namespace xlnt { class alignment; class border; class cell; class cell_style; class color; class const_worksheet_iterator; class drawing; class fill; class font; class format; class manifest; class named_range; class number_format; class path; class pattern_fill; class protection; class range; class range_reference; class relationship; class style; class style_serializer; class text; class theme; class worksheet; class worksheet_iterator; class zip_file; struct datetime; enum class calendar; enum class relationship_type; namespace detail { struct workbook_impl; } // namespace detail /// /// workbook is the container for all other parts of the document. /// class XLNT_CLASS workbook { public: using iterator = worksheet_iterator; using const_iterator = const_worksheet_iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; /// /// Swap the data held in workbooks "left" and "right". /// friend void swap(workbook &left, workbook &right); static workbook minimal(); static workbook empty_excel(); static workbook empty_libre_office(); static workbook empty_numbers(); // 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 /// /// 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 /// /// Create a sheet after the last sheet in this workbook and return it. /// worksheet create_sheet(); /// /// Create a sheet at the specified index and return it. /// worksheet create_sheet(std::size_t index); /// /// This should be private... /// worksheet create_sheet_with_rel(const std::string &title, const relationship &rel); /// /// Create a new sheet initializing it with all of the data from the provided worksheet. /// void copy_sheet(worksheet worksheet); /// /// Create a new sheet at the specified index initializing it with all of the data /// from the provided 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 the given worksheet from this workbook. /// void remove_sheet(worksheet worksheet); /// /// Delete every cell in this worksheet. After this is called, the /// worksheet will be equivalent to a newly created sheet at the same /// index and with the same title. /// void clear(); // iterators /// /// Returns an iterator to the first worksheet in this workbook. /// iterator begin(); /// /// Returns an iterator to the worksheet following the last worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// iterator end(); /// /// Returns a const iterator to the first worksheet in this workbook. /// const_iterator begin() const; /// /// Returns a const iterator to the worksheet following the last worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// const_iterator end() const; /// /// Returns an iterator to the first worksheet in this workbook. /// const_iterator cbegin() const; /// /// Returns a const iterator to the worksheet following the last worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// const_iterator cend() const; /// /// Returns a reverse iterator to the last worksheet in this workbook. /// reverse_iterator rbegin(); /// /// Returns an iterator to the worksheet preceeding the first worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// reverse_iterator rend(); /// /// Returns a const reverse iterator to the last worksheet in this workbook. /// const_reverse_iterator rbegin() const; /// /// Returns a const reverse iterator to the worksheet preceeding the first worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// const_reverse_iterator rend() const; /// /// Returns a const reverse iterator to the last worksheet in this workbook. /// const_reverse_iterator crbegin() const; /// /// Returns a const reverse iterator to the worksheet preceeding the first worksheet of the workbook. /// This worksheet acts as a placeholder; attempting to access it will cause an /// exception to be thrown. /// const_reverse_iterator crend() const; /// /// 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::string get_application() const; void set_application(const std::string &application); calendar get_base_date() const; void set_base_date(calendar base_date); std::string get_creator() const; void set_creator(const std::string &creator); std::string get_last_modified_by() const; void set_last_modified_by(const std::string &last_modified_by); 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); // 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); bool has_named_range(const std::string &name) const; range get_named_range(const std::string &name); void remove_named_range(const std::string &name); // serialization bool save(std::vector &data); bool save(const std::string &filename); bool save(const xlnt::path &filename); bool save(std::ostream &stream); bool load(const std::vector &data); bool load(const std::string &filename); bool load(const xlnt::path &filename); bool load(std::istream &stream); void set_code_name(const std::string &code_name); // theme bool has_theme() const; const theme &get_theme() const; void set_theme(const theme &value); // formats format &get_format(std::size_t format_index); const format &get_format(std::size_t format_index) const; std::size_t add_format(const format &new_format); void clear_formats(); // 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; style &get_style_by_id(std::size_t style_id); const style &get_style_by_id(std::size_t style_id) const; std::size_t get_style_id(const std::string &name) const; style &create_style(const std::string &name); std::size_t add_style(const style &new_style); void clear_styles(); const std::vector