// Copyright (c) 2014-2018 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 namespace xlnt { enum class calendar; /// /// Describes the number formatting applied to text and numbers within a certain cell. /// class XLNT_API number_format { public: /// /// Number format "General" /// static const number_format general(); /// /// Number format "@" /// static const number_format text(); /// /// Number format "0" /// static const number_format number(); /// /// Number format "00" /// static const number_format number_00(); /// /// Number format "#,##0.00" /// static const number_format number_comma_separated1(); /// /// Number format "0%" /// static const number_format percentage(); /// /// Number format "0.00%" /// static const number_format percentage_00(); /// /// Number format "yyyy-mm-dd" /// static const number_format date_yyyymmdd2(); /// /// Number format "yy-mm-dd" /// static const number_format date_yymmdd(); /// /// Number format "dd/mm/yy" /// static const number_format date_ddmmyyyy(); /// /// Number format "d/m/yy" /// static const number_format date_dmyslash(); /// /// Number format "d-m-yy" /// static const number_format date_dmyminus(); /// /// Number format "d-m" /// static const number_format date_dmminus(); /// /// Number format "m-yy" /// static const number_format date_myminus(); /// /// Number format "mm-dd-yy" /// static const number_format date_xlsx14(); /// /// Number format "d-mmm-yy" /// static const number_format date_xlsx15(); /// /// Number format "d-mmm" /// static const number_format date_xlsx16(); /// /// Number format "mmm-yy" /// static const number_format date_xlsx17(); /// /// Number format "m/d/yy h:mm" /// static const number_format date_xlsx22(); /// /// Number format "yyyy-mm-dd h:mm:ss" /// static const number_format date_datetime(); /// /// Number format "h:mm AM/PM" /// static const number_format date_time1(); /// /// Number format "h:mm:ss AM/PM" /// static const number_format date_time2(); /// /// Number format "h:mm" /// static const number_format date_time3(); /// /// Number format "h:mm:ss" /// static const number_format date_time4(); /// /// Number format "mm:ss" /// static const number_format date_time5(); /// /// Number format "h:mm:ss" /// static const number_format date_time6(); /// /// Returns true if the given format ID corresponds to a known builtin format. /// static bool is_builtin_format(std::size_t builtin_id); /// /// Returns the format with the given ID. Thows an invalid_parameter exception /// if builtin_id is not a valid ID. /// static const number_format &from_builtin_id(std::size_t builtin_id); /// /// Constructs a default number_format equivalent to "General" /// number_format(); /// /// Constructs a number format equivalent to that returned from number_format::from_builtin_id(builtin_id). /// number_format(std::size_t builtin_id); /// /// Constructs a number format from a code string. If the string matches a builtin ID, /// its ID will also be set to match the builtin ID. /// number_format(const std::string &code); /// /// Constructs a number format from a code string and custom ID. Custom ID should generally /// be >= 164. /// number_format(const std::string &code, std::size_t custom_id); /// /// Sets the format code of this number format to format_code. /// void format_string(const std::string &format_code); /// /// Sets the format code of this number format to format_code and the ID to custom_id. /// void format_string(const std::string &format_code, std::size_t custom_id); /// /// Returns the format code this number format uses. /// std::string format_string() const; /// /// Returns true if this number format has an ID. /// bool has_id() const; /// /// Sets the ID of this number format to id. /// void id(std::size_t id); /// /// Returns the ID of this format. /// std::size_t id() const; /// /// Returns text formatted according to this number format's format code. /// std::string format(const std::string &text) const; /// /// Returns number formatted according to this number format's format code /// with the given base date. /// std::string format(double number, calendar base_date) const; /// /// Returns true if this format code returns a number formatted as a date. /// bool is_date_format() const; /// /// Returns true if this format is equivalent to other. /// bool operator==(const number_format &other) const; /// /// Returns true if this format is not equivalent to other. /// bool operator!=(const number_format &other) const; private: /// /// The optional ID /// optional id_; /// /// The format code /// std::string format_string_; }; } // namespace xlnt