OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLStyles.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_HPP
12#define OPENXLSX_XLSTYLES_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20// Umbrella header: styles subsystem split into subdomain headers.
21// Existing code may keep #include "XLStyles.hpp".
22// Dependency order: Common -> pools (NumberFormats/Fonts/Fills) -> Borders (needs XLDataBarColor)
23// -> CellFormats/CellStyles -> Dxfs (aggregates several pools).
24
25#include "XLStyles_Common.hpp"
27#include "XLStyles_Fonts.hpp"
28#include "XLStyles_Fills.hpp"
29#include "XLStyles_Borders.hpp"
32#include "XLStyles_Dxfs.hpp"
33
34#include "XLXmlFile.hpp"
35
36#include <gsl/gsl>
37#include <memory>
38#include <optional>
39#include <string>
40#include <string_view>
41
42namespace OpenXLSX
43{
44 // XLStyles Class
45
49 class OPENXLSX_EXPORT XLStyles : public XLXmlFile
50 {
51 public: // ---------- Public Member Functions ---------- //
55 XLStyles();
56
64 explicit XLStyles(gsl::not_null<XLXmlData*> xmlData,
65 bool suppressWarnings = false,
66 std::string_view stylesPrefix = XLDefaultStylesPrefix);
67
72
77 XLStyles(XLStyles&& other) noexcept;
78
83 XLStyles(const XLStyles& other);
84
90 XLStyles& operator=(XLStyles&& other) noexcept;
91
97 XLStyles& operator=(const XLStyles& other);
98
104 uint32_t createNumberFormat(std::string_view formatCode);
105
111
116 XLFonts& fonts() const;
117
122 XLFills& fills() const;
123
128 XLBorders& borders() const;
129
135
140 XLCellFormats& cellFormats() const;
141
146 XLCellStyles& cellStyles() const;
147
152 XLDxfs& dxfs() const;
153
157 XLDxfs& diffCellFormats() const { return dxfs(); }
158
164 XLStyleIndex addDxf(const XLDxf& dxf);
165
175 XLStyleIndex addNamedStyle(std::string_view name,
176 std::optional<XLStyleIndex> fontId = std::nullopt,
177 std::optional<XLStyleIndex> fillId = std::nullopt,
178 std::optional<XLStyleIndex> borderId = std::nullopt,
179 std::optional<XLStyleIndex> numFmtId = std::nullopt);
180
186 XLStyleIndex namedStyle(std::string_view name) const;
187
198 XLStyleIndex findOrCreateStyle(const XLStyle& style);
199
205 void compactStyles();
206
207 // ---------- Protected Member Functions ---------- //
208 private:
209 struct StyleCacheImpl;
210
211 bool m_suppressWarnings; // if true, will suppress output of warnings where supported
212 std::unique_ptr<XLNumberFormats> m_numberFormats; // handle to the underlying number formats
213 std::unique_ptr<XLFonts> m_fonts; // handle to the underlying fonts
214 std::unique_ptr<XLFills> m_fills; // handle to the underlying fills
215 std::unique_ptr<XLBorders> m_borders; // handle to the underlying border descriptions
216 std::unique_ptr<XLCellFormats> m_cellStyleFormats; // handle to the underlying cell style formats descriptions
217 std::unique_ptr<XLCellFormats> m_cellFormats; // handle to the underlying cell formats descriptions
218 std::unique_ptr<XLCellStyles> m_cellStyles; // handle to the underlying cell styles
219 std::unique_ptr<XLDxfs> m_dxfs; // handle to the underlying differential cell formats
220 std::unique_ptr<StyleCacheImpl> m_styleCache; // thread-safe top-level XLStyle -> XLStyleIndex cache
221 };
222} // namespace OpenXLSX
223
224#ifdef _MSC_VER
225# pragma warning(pop)
226#endif
227
228#endif // OPENXLSX_XLSTYLES_HPP
An encapsulation of the XLSX borders.
Definition XLStyles_Borders.hpp:254
An encapsulation of the XLSX cell style formats.
Definition XLStyles_CellFormats.hpp:375
An encapsulation of the XLSX cell styles.
Definition XLStyles_CellStyles.hpp:158
Definition XLStyles_Dxfs.hpp:36
An encapsulation of the XLSX differential cell formats (dxfs).
Definition XLStyles_Dxfs.hpp:151
An encapsulation of the XLSX fills.
Definition XLStyles_Fills.hpp:417
An encapsulation of the XLSX fonts.
Definition XLStyles_Fonts.hpp:205
An encapsulation of the XLSX number formats (numFmts).
Definition XLStyles_NumberFormats.hpp:114
XLCellStyles & cellStyles() const
Get the cell styles object.
Definition XLStyles.cpp:280
XLBorders & borders() const
Get the borders object.
Definition XLStyles.cpp:274
XLCellFormats & cellFormats() const
Get the cell formats object.
Definition XLStyles.cpp:278
XLFills & fills() const
Get the fills object.
Definition XLStyles.cpp:272
XLCellFormats & cellStyleFormats() const
Get the cell style formats object.
Definition XLStyles.cpp:276
uint32_t createNumberFormat(std::string_view formatCode)
Create a new custom number format with a unique ID and format code.
Definition XLStyles.cpp:266
XLDxfs & dxfs() const
Get the differential cell formats object (dxfs).
Definition XLStyles.cpp:282
XLFonts & fonts() const
Get the fonts object.
Definition XLStyles.cpp:270
XLStyles()
Definition XLStyles.cpp:90
XLStyles & operator=(XLStyles &&other) noexcept
move assignment
Definition XLStyles.cpp:239
~XLStyles()
Destructor.
XLNumberFormats & numberFormats() const
Get the number formats object.
Definition XLStyles.cpp:268
XLDxfs & diffCellFormats() const
Backward compatibility alias for dxfs().
Definition XLStyles.hpp:157
std::string xmlData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Method for getting the XML data represented by the object.
Definition XLXmlFile.cpp:49
XLXmlFile()=default
Default constructor.
Definition IXLCellProvider.hpp:24
constexpr const char * XLDefaultStylesPrefix
Definition XLStyles_Common.hpp:51
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36
A high-level, human-ergonomic structure representing the styling of a cell or range....
Definition XLStyle.hpp:29