xlnt - community edition
number_format.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024-2026 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 <string>
29 
30 #include <xlnt/xlnt_config.hpp>
31 #include <xlnt/utils/optional.hpp>
32 
33 namespace xlnt {
34 
35 enum class calendar;
36 
40 class XLNT_API number_format
41 {
42 public:
46  static const number_format general();
47 
51  static const number_format text();
52 
56  static const number_format number();
57 
61  static const number_format number_00();
62 
66  static const number_format number_comma_separated1();
67 
71  static const number_format percentage();
72 
76  static const number_format percentage_00();
77 
81  static const number_format date_yyyymmdd2();
82 
86  static const number_format date_yymmdd();
87 
91  static const number_format date_ddmmyyyy();
92 
96  static const number_format date_dmyslash();
97 
101  static const number_format date_dmyminus();
102 
106  static const number_format date_dmminus();
107 
111  static const number_format date_myminus();
112 
116  static const number_format date_xlsx14();
117 
121  static const number_format date_xlsx15();
122 
126  static const number_format date_xlsx16();
127 
131  static const number_format date_xlsx17();
132 
136  static const number_format date_xlsx22();
137 
141  static const number_format date_datetime();
142 
146  static const number_format date_time1();
147 
151  static const number_format date_time2();
152 
156  static const number_format date_time3();
157 
161  static const number_format date_time4();
162 
166  static const number_format date_time5();
167 
171  static const number_format date_time6();
172 
178  static bool is_builtin_format(std::size_t builtin_id);
179 
187  static const number_format &from_builtin_id(std::size_t builtin_id);
188 
192  number_format();
193 
199  number_format(std::size_t builtin_id);
200 
205  number_format(const std::string &code);
206 
212  number_format(const std::string &code, std::size_t custom_id);
213 
217  void format_string(const std::string &format_code);
218 
224  void format_string(const std::string &format_code, std::size_t custom_id);
225 
229  std::string format_string() const;
230 
234  bool has_id() const;
235 
241  void id(std::size_t id);
242 
250  std::size_t id() const;
251 
255  std::string format(const std::string &text) const;
256 
261  std::string format(double number, calendar base_date) const;
262 
266  bool is_date_format() const;
267 
271  bool operator==(const number_format &other) const;
272 
276  bool operator!=(const number_format &other) const;
277 
278 private:
285 
289  std::string format_string_;
290 };
291 
292 } // namespace xlnt
value is a number
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:36
bool operator!=(std::nullptr_t, const cell &cell)
Returns true if this cell is initialized.
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:40
Describes the formatting of a particular cell.
Definition: format.hpp:58
calendar
An enumeration of possible base dates. Dates in Excel are stored as days since this base date...
Definition: calendar.hpp:35