xlnt
number_format.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024 xlnt-community
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE
22 //
23 // @license: http://www.opensource.org/licenses/mit-license.php
24 // @author: see AUTHORS file
25 
26 #pragma once
27 
28 #include <cstdint>
29 #include <string>
30 
31 #include <xlnt/xlnt_config.hpp>
32 #include <xlnt/utils/optional.hpp>
33 
34 namespace xlnt {
35 
36 enum class calendar;
37 
41 class XLNT_API number_format
42 {
43 public:
47  static const number_format general();
48 
52  static const number_format text();
53 
57  static const number_format number();
58 
62  static const number_format number_00();
63 
67  static const number_format number_comma_separated1();
68 
72  static const number_format percentage();
73 
77  static const number_format percentage_00();
78 
82  static const number_format date_yyyymmdd2();
83 
87  static const number_format date_yymmdd();
88 
92  static const number_format date_ddmmyyyy();
93 
97  static const number_format date_dmyslash();
98 
102  static const number_format date_dmyminus();
103 
107  static const number_format date_dmminus();
108 
112  static const number_format date_myminus();
113 
117  static const number_format date_xlsx14();
118 
122  static const number_format date_xlsx15();
123 
127  static const number_format date_xlsx16();
128 
132  static const number_format date_xlsx17();
133 
137  static const number_format date_xlsx22();
138 
142  static const number_format date_datetime();
143 
147  static const number_format date_time1();
148 
152  static const number_format date_time2();
153 
157  static const number_format date_time3();
158 
162  static const number_format date_time4();
163 
167  static const number_format date_time5();
168 
172  static const number_format date_time6();
173 
177  static bool is_builtin_format(std::size_t builtin_id);
178 
183  static const number_format &from_builtin_id(std::size_t builtin_id);
184 
188  number_format();
189 
193  number_format(std::size_t builtin_id);
194 
199  number_format(const std::string &code);
200 
205  number_format(const std::string &code, std::size_t custom_id);
206 
210  void format_string(const std::string &format_code);
211 
215  void format_string(const std::string &format_code, std::size_t custom_id);
216 
220  std::string format_string() const;
221 
225  bool has_id() const;
226 
230  void id(std::size_t id);
231 
235  std::size_t id() const;
236 
240  std::string format(const std::string &text) const;
241 
246  std::string format(double number, calendar base_date) const;
247 
251  bool is_date_format() const;
252 
256  bool operator==(const number_format &other) const;
257 
261  bool operator!=(const number_format &other) const;
262 
263 private:
268 
272  std::string format_string_;
273 };
274 
275 } // namespace xlnt
value is a number
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Describes the number formatting applied to text and numbers within a certain cell.
Definition: number_format.hpp:41
Describes the formatting of a particular cell.
Definition: format.hpp:58
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.
calendar
An enumeration of possible base dates. Dates in Excel are stored as days since this base date...
Definition: calendar.hpp:35