// 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 // for XLNT_API, XLNT_API #include // for cell_type #include // for column_t, row_t namespace xlnt { enum class calendar; class alignment; class base_format; class border; class cell_reference; class comment; class fill; class font; class format; class number_format; class protection; class style; class workbook; class worksheet; class xlsx_consumer; class xlsx_producer; struct date; struct datetime; struct time; struct timedelta; namespace detail { class xlsx_consumer; class xlsx_producer; struct cell_impl; } // namespace detail /// /// Describes cell associated properties. /// /// /// Properties of interest include style, type, value, and address. /// The Cell class is required to know its value and type, display options, /// and any other features of an Excel cell.Utilities for referencing /// cells using Excel's 'A1' column/row nomenclature are also provided. /// class XLNT_API cell { public: using type = cell_type; /// /// Return a map of error strings such as \#DIV/0! and their associated indices. /// static const std::unordered_map &error_codes(); // value /// /// Return true if value has been set and has not been cleared using cell::clear_value(). /// bool has_value() const; /// /// Return the value of this cell as an instance of type T. /// Overloads exist for most C++ fundamental types like bool, int, etc. as well /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. /// template T get_value() const; /// /// Make this cell have a value of type null. /// All other cell attributes are retained. /// void clear_value(); /// /// Set the value of this cell to the given value. /// Overloads exist for most C++ fundamental types like bool, int, etc. as well /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. /// template void set_value(T value); /// /// Return the type of this cell. /// type get_data_type() const; /// /// Set the type of this cell. /// void set_data_type(type t); // properties /// /// There's no reason to keep a cell which has no value and is not a placeholder. /// Return true if this cell has no value, style, isn't merged, etc. /// bool garbage_collectible() const; /// /// Return true iff this cell's number format matches a date format. /// bool is_date() const; // position /// /// Return a cell_reference that points to the location of this cell. /// cell_reference get_reference() const; /// /// Return the column of this cell. /// column_t get_column() const; /// /// Return the row of this cell. /// row_t get_row() const; /// /// Return the location of this cell as an ordered pair. /// std::pair get_anchor() const; // hyperlink /// /// Return the URL of this cell's hyperlink. /// std::string get_hyperlink() const; /// /// Add a hyperlink to this cell pointing to the URI of the given value. /// void set_hyperlink(const std::string &value); /// /// Return true if this cell has a hyperlink set. /// bool has_hyperlink() const; // computed format /// /// For each of alignment, border, fill, font, number format, and protection, /// returns a format using the value from the cell format if that value is /// applied, or else the value from the named style if that value is applied, /// or else the default value. This is used to retreive the formatting of the cell /// as it will be displayed in an editing application. /// base_format get_computed_format() const; /// /// Returns the result of get_computed_format().get_alignment(). /// alignment get_computed_alignment() const; /// /// Returns the result of get_computed_format().get_border(). /// border get_computed_border() const; /// /// Returns the result of get_computed_format().get_fill(). /// fill get_computed_fill() const; /// /// Returns the result of get_computed_format().get_font(). /// font get_computed_font() const; /// /// Returns the result of get_computed_format().get_number_format(). /// number_format get_computed_number_format() const; /// /// Returns the result of get_computed_format().get_protection(). /// protection get_computed_protection() const; // format /// /// Return true if this cell has had a format applied to it. /// bool has_format() const; /// /// Return a reference to the format applied to this cell. /// If this cell has no format, an invalid_attribute exception will be thrown. /// format get_format() const; /// /// Applies the cell-level formatting of new_format to this cell. /// void set_format(const format &new_format); /// /// Remove the cell-level formatting from this cell. /// This doesn't affect the style that may also be applied to the cell. /// Throws an invalid_attribute exception if no format is applied. /// void clear_format(); /// /// Returns the number format of this cell. /// number_format get_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); /// /// Returns the font applied to the text in this cell. /// font get_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_); /// /// Returns the fill applied to this cell. /// fill get_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_); /// /// Returns the border of this cell. /// border get_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_); /// /// Returns the alignment of the text in this cell. /// alignment get_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_); /// /// Returns the protection of this cell. /// protection get_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_); // style /// /// Returns true if this cell has had a style applied to it. /// bool has_style() const; /// /// Returns a reference to the named style applied to this cell. /// style get_style() const; /// /// Equivalent to set_style(new_style.name()) /// void set_style(const style &new_style); /// /// Sets the named style applied to this cell to a style named style_name. /// If this style has not been previously created in the workbook, a /// key_not_found exception will be thrown. /// void set_style(const std::string &style_name); /// /// Removes the named style from this cell. /// An invalid_attribute exception will be thrown if this cell has no style. /// This will not affect the cell format of the cell. /// void clear_style(); // formula /// /// Returns the string representation of the formula applied to this cell. /// std::string get_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); /// /// Removes the formula from this cell. After this is called, has_formula() will return false. /// void clear_formula(); /// /// Returns true if this cell has had a formula applied to it. /// bool has_formula() const; // printing /// /// Returns a string describing this cell like . /// std::string to_repr() const; /// /// Returns a string representing the value of this cell. If the data type is not a string, /// it will be converted according to the number format. /// std::string to_string() const; // merging /// /// Return true iff this cell has been merged with one or more /// surrounding cells. /// bool is_merged() const; /// /// Make this a merged cell iff merged is true. /// Generally, this shouldn't be called directly. Instead, /// use worksheet::merge_cells on its parent worksheet. /// void set_merged(bool merged); /// /// Return the error string that is stored in this cell. /// std::string get_error() const; /// /// Directly assign the value of this cell to be the given error. /// void set_error(const std::string &error); /// /// Return a cell from this cell's parent workbook at /// a relative offset given by the parameters. /// cell offset(int column, int row); /// /// Return the worksheet that owns this cell. /// worksheet get_worksheet(); /// /// Return the worksheet that owns this cell. /// const worksheet get_worksheet() const; /// /// Return the workbook of the worksheet that owns this cell. /// workbook &get_workbook(); /// /// Return the workbook of the worksheet that owns this cell. /// const workbook &get_workbook() const; /// /// Shortcut to return the base date of the parent workbook. /// Equivalent to get_workbook().get_properties().excel_base_date /// calendar get_base_date() const; /// /// Return to_check after checking encoding, size, and illegal characters. /// std::string check_string(const std::string &to_check); // comment /// /// Return true if this cell has a comment applied. /// bool has_comment(); /// /// Delete the comment applied to this cell if it exists. /// void clear_comment(); /// /// Get the comment applied to this cell. /// class comment comment(); /// /// Apply the comment provided as the ony argument to the cell. /// void comment(const class comment &new_comment); // operators /// /// Make this cell point to rhs. /// The cell originally pointed to by this cell will be unchanged. /// cell &operator=(const cell &rhs); /// /// Return true if this cell the same cell as comparand (compare by reference). /// bool operator==(const cell &comparand) const; /// /// Return true if this cell is uninitialized. /// bool operator==(std::nullptr_t) const; // friend operators, so we can put cell on either side of comparisons with other types /// /// Return true if this cell is uninitialized. /// friend XLNT_API bool operator==(std::nullptr_t, const cell &cell); /// /// Convenience function for writing cell to an ostream. /// Uses cell::to_string() internally. /// friend XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell); private: // make these friends so they can use the private constructor friend class style; friend class worksheet; friend class detail::xlsx_consumer; 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. /// format &get_format_internal(); /// /// Use workbook::create_format() to create a new format then copy /// this cell's formatting to that new format and return it. /// format &duplicate_format(); /// /// Private constructor to create a cell from its implementation. /// cell(detail::cell_impl *d); /// /// A pointer to this cell's implementation. /// detail::cell_impl *d_; }; } // namespace xlnt