// 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 { enum class calendar; enum class relationship_type; class alignment; class border; class calculation_properties; class cell; class cell_style; class color; class const_worksheet_iterator; class drawing; class fill; class font; class format; class rich_text; 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 theme; class workbook_view; class worksheet; class worksheet_iterator; class zip_file; struct datetime; namespace detail { struct stylesheet; struct workbook_impl; class xlsx_consumer; class xlsx_producer; } // namespace detail /// /// workbook is the container for all other parts of the document. /// class XLNT_API 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(); // 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 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 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 sheet_by_title(const std::string &sheet_name) const; /// /// Return the worksheet at the given index. /// worksheet sheet_by_index(std::size_t index); /// /// Return the const worksheet at the given index. /// const worksheet sheet_by_index(std::size_t index) const; /// /// Return the worksheet with a sheetId of id. /// worksheet sheet_by_id(std::size_t id); /// /// Return the const worksheet with a sheetId of id. /// const worksheet sheet_by_id(std::size_t id) 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 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; /// /// Apply the function "f" to every non-empty cell in every worksheet in this workbook. /// void apply_to_cells(std::function f); /// /// Returns a temporary vector containing the titles of each sheet in the order /// of the sheets in the workbook. /// std::vector sheet_titles() const; /// /// Returns the number of sheets in this workbook. /// std::size_t sheet_count() const; /// /// Returns true if the workbook has the core property with the given name. /// bool has_core_property(const std::string &property_name) const; /// /// /// template T core_property(const std::string &property_name) const; /// /// /// template void core_property(const std::string &property_name, const T value); /// /// /// calendar base_date() const; /// /// /// void base_date(calendar base_date); /// /// /// bool has_title() const; /// /// /// std::string title() const; /// /// /// void title(const std::string &title); // named ranges /// /// /// std::vector 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; /// /// /// class range named_range(const std::string &name); /// /// /// void remove_named_range(const std::string &name); // serialization /// /// /// void save(std::vector &data) const; /// /// /// void save(const std::string &filename) const; /// /// /// void save(const xlnt::path &filename) const; /// /// /// void save(std::ostream &stream) const; /// /// /// void save(const std::string &filename, const std::string &password); /// /// /// void save(const xlnt::path &filename, const std::string &password); /// /// /// void save(std::ostream &stream, const std::string &password); /// /// /// void save(const std::vector &data, const std::string &password); /// /// /// void load(const std::vector &data); /// /// /// void load(const std::string &filename); /// /// /// void load(const xlnt::path &filename); /// /// /// void load(std::istream &stream); /// /// /// void load(const std::string &filename, const std::string &password); /// /// /// void load(const xlnt::path &filename, const std::string &password); /// /// /// void load(std::istream &stream, const std::string &password); /// /// /// void load(const std::vector &data, const std::string &password); #ifdef _MSC_VER /// /// /// void save(const std::wstring &filename); /// /// /// void save(const std::wstring &filename, const std::string &password); /// /// /// void load(const std::wstring &filename); /// /// /// void load(const std::wstring &filename, const std::string &password); #endif /// /// /// bool has_view() const; /// /// /// workbook_view view() const; /// /// /// void view(const workbook_view &view); /// /// /// bool has_code_name() const; /// /// /// std::string code_name() const; /// /// /// void code_name(const std::string &code_name); /// /// /// bool has_file_version() const; /// /// /// std::string app_name() const; /// /// /// std::size_t last_edited() const; /// /// /// std::size_t lowest_edited() const; /// /// /// std::size_t rup_build() const; // theme /// /// /// bool has_theme() const; /// /// /// const xlnt::theme &theme() const; /// /// /// void theme(const class theme &value); // formats /// /// /// xlnt::format format(std::size_t format_index); /// /// /// const xlnt::format format(std::size_t format_index) const; /// /// /// xlnt::format create_format(bool default_format = false); /// /// /// void clear_formats(); // styles /// /// /// bool has_style(const std::string &name) const; /// /// /// class style style(const std::string &name); /// /// /// const class style style(const std::string &name) const; /// /// /// class style create_style(const std::string &name); /// /// /// void clear_styles(); // manifest /// /// /// class manifest &manifest(); /// /// /// const class manifest &manifest() const; // shared strings /// /// /// void add_shared_string(const rich_text &shared, bool allow_duplicates = false); /// /// /// std::vector &shared_strings(); /// /// /// const std::vector &shared_strings() const; // thumbnail /// /// /// void thumbnail(const std::vector &thumbnail, const std::string &extension, const std::string &content_type); /// /// /// const std::vector &thumbnail() const; // calculation properties /// /// /// bool has_calculation_properties() const; /// /// /// class calculation_properties calculation_properties() const; /// /// /// void calculation_properties(const class calculation_properties &props); // operators /// /// Set the contents of this workbook to be equal to those of "other". /// Other is passed as value to allow for copy-swap idiom. /// workbook &operator=(workbook other); /// /// Return the worksheet with a title of "name". /// worksheet operator[](const std::string &name); /// /// Return the worksheet at "index". /// worksheet operator[](std::size_t index); /// /// Return true if this workbook internal implementation points to the same /// memory as rhs's. /// bool operator==(const workbook &rhs) const; /// /// Return true if this workbook internal implementation doesn't point to the same /// memory as rhs's. /// bool operator!=(const workbook &rhs) const; private: friend class worksheet; friend class detail::xlsx_consumer; friend class detail::xlsx_producer; /// /// /// workbook(detail::workbook_impl *impl); /// /// /// detail::workbook_impl &impl(); /// /// /// const detail::workbook_impl &impl() const; /// /// /// void register_app_properties_in_manifest(); /// /// /// void register_core_properties_in_manifest(); /// /// /// void register_shared_string_table_in_manifest(); /// /// /// void register_stylesheet_in_manifest(); /// /// /// void register_theme_in_manifest(); /// /// /// void register_comments_in_manifest(worksheet ws); /// /// An opaque pointer to a structure that holds all of the data relating to this workbook. /// std::unique_ptr d_; }; } // namespace xlnt