OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLStyles_NumberFormats.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLSTYLES_NUMBERFORMATS_HPP
12#define OPENXLSX_XLSTYLES_NUMBERFORMATS_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20#include "XLStyles_Common.hpp"
21#include "XLColor.hpp"
22#include "XLXmlParser.hpp"
23
24#include <memory>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <unordered_map>
29#include <vector>
30
31
32namespace OpenXLSX
33{
34 class OPENXLSX_EXPORT XLNumberFormat
35 {
36 friend class XLNumberFormats; // for access to m_numberFormatNode in XLNumberFormats::create
37 public: // ---------- Public Member Functions ---------- //
42
47 explicit XLNumberFormat(const XMLNode& node);
48
53 XLNumberFormat(const XLNumberFormat& other);
54
59 XLNumberFormat(XLNumberFormat&& other) noexcept = default;
60
65
72
78 XLNumberFormat& operator=(XLNumberFormat&& other) noexcept = default;
79
84 uint32_t numberFormatId() const;
85
90 std::string formatCode() const;
91
97 bool setNumberFormatId(uint32_t newNumberFormatId);
98 bool setFormatCode(std::string_view newFormatCode);
99
104 std::string summary() const;
105
106 private: // ---------- Private Member Variables ---------- //
107 std::unique_ptr<XMLNode> m_numberFormatNode;
108 };
109
113 class OPENXLSX_EXPORT XLNumberFormats
114 {
115 public: // ---------- Public Member Functions ---------- //
120
125 explicit XLNumberFormats(const XMLNode& node);
126
131 XLNumberFormats(const XLNumberFormats& other);
132
138
143
150
156 XLNumberFormats& operator=(XLNumberFormats&& other) noexcept = default;
157
162 size_t count() const;
163
171
176
183 XLNumberFormat numberFormatById(uint32_t numberFormatId) const;
184
191 uint32_t numberFormatIdFromIndex(XLStyleIndex index) const;
192
197 static std::optional<uint32_t> standardNumberFormatId(std::string_view formatCode) noexcept;
198
203 static std::string_view standardFormatCode(uint32_t id) noexcept;
204
210 uint32_t createNumberFormat(std::string_view formatCode);
211
216 uint32_t getFreeNumberFormatId() const;
217
224 XLStyleIndex create(XLNumberFormat copyFrom = XLNumberFormat{}, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
225
226 private: // ---------- Private Member Variables ---------- //
227 std::unique_ptr<XMLNode> m_numberFormatsNode;
228 std::vector<XLNumberFormat> m_numberFormats;
229 };
230
231} // namespace OpenXLSX
232
233#ifdef _MSC_VER
234# pragma warning(pop)
235#endif
236
237#endif // OPENXLSX_XLSTYLES_NUMBERFORMATS_HPP
Definition XLStyles_NumberFormats.hpp:35
XLNumberFormat()
Definition XLStyles_NumberFormats.cpp:30
uint32_t numberFormatId() const
Get the id of the number format.
Definition XLStyles_NumberFormats.cpp:44
bool setFormatCode(std::string_view newFormatCode)
Definition XLStyles_NumberFormats.cpp:50
XLNumberFormat & operator=(const XLNumberFormat &other)
Copy assignment operator.
Definition XLStyles_NumberFormats.cpp:38
std::string formatCode() const
Get the code of the number format.
Definition XLStyles_NumberFormats.cpp:46
std::string summary() const
Return a string summary of the number format.
Definition XLStyles_NumberFormats.cpp:53
bool setNumberFormatId(uint32_t newNumberFormatId)
Setter functions for style parameters.
Definition XLStyles_NumberFormats.cpp:48
XLNumberFormat & operator=(XLNumberFormat &&other) noexcept=default
Move assignment operator.
friend class XLNumberFormats
Definition XLStyles_NumberFormats.hpp:36
XLNumberFormat(XLNumberFormat &&other) noexcept=default
Move Constructor.
XLNumberFormats()
Definition XLStyles_NumberFormats.cpp:57
XLNumberFormat operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to numberFormatByIndex.
Definition XLStyles_NumberFormats.hpp:175
XLNumberFormats & operator=(XLNumberFormats &&other) noexcept=default
Move assignment operator.
size_t count() const
Get the count of number formats.
Definition XLStyles_NumberFormats.cpp:95
XLNumberFormats & operator=(const XLNumberFormats &other)
Copy assignment operator.
Definition XLStyles_NumberFormats.cpp:85
XLNumberFormat numberFormatByIndex(XLStyleIndex index) const
Get the number format identified by index.
Definition XLStyles_NumberFormats.cpp:97
Definition IXLCellProvider.hpp:24
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36