OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLContentTypes.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_XLCONTENTTYPES_HPP
12#define OPENXLSX_XLCONTENTTYPES_HPP
13
14#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif // _MSC_VER
19
20// ===== External Includes ===== //
21#include <cstdint> // uint8_t
22#include <gsl/pointers>
23#include <memory>
24#include <string>
25#include <string_view>
26#include <vector>
27
28// ===== OpenXLSX Includes ===== //
29#include "OpenXLSX-Exports.hpp"
30#include "XLXmlFile.hpp"
31#include "XLXmlParser.hpp"
32
33namespace OpenXLSX
34{
71
78
79 class OPENXLSX_EXPORT XLContentItem
80 {
81 friend class XLContentTypes;
82
83 public: // ---------- Public Member Functions ---------- //
85
86 explicit XLContentItem(const XMLNode& node);
87
88 ~XLContentItem() = default;
89
90 XLContentItem(const XLContentItem& other);
91
92 XLContentItem(XLContentItem&& other) noexcept;
93
95
97
98 XLContentType type() const;
99
100 std::string path() const;
101
102 private:
103 std::unique_ptr<XMLNode> m_contentNode;
104 };
105
106 // XLContentTypes Class
107
111 class OPENXLSX_EXPORT XLContentTypes : public XLXmlFile
112 {
113 public: // ---------- Public Member Functions ---------- //
115
116 explicit XLContentTypes(gsl::not_null<XLXmlData*> xmlData);
117
118 ~XLContentTypes() = default;
119
121
123
125
127
133 bool hasDefault(std::string_view extension) const;
134
140 bool hasOverride(std::string_view path) const;
141
147 void addDefault(std::string_view extension, std::string_view contentType);
148
154 void addOverride(std::string_view path, XLContentType type);
155
161 void updateOverride(std::string_view path, XLContentType type);
162
163 void deleteOverride(std::string_view path);
164
165 void deleteOverride(const XLContentItem& item);
166
171 void deleteDefault(std::string_view extension);
172
173 XLContentItem contentItem(std::string_view path);
174
175 std::vector<XLContentItem> getContentItems();
176
177 private: // ---------- Private Member Variables ---------- //
178 };
179} // namespace OpenXLSX
180
181#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
182# pragma warning(pop)
183#endif // _MSC_VER
184
185#endif // OPENXLSX_XLCONTENTTYPES_HPP
Definition XLContentTypes.hpp:80
XLContentItem(XLContentItem &&other) noexcept
XLContentItem & operator=(const XLContentItem &other)
Definition XLContentTypes.cpp:145
XLContentItem()
Definition XLContentTypes.cpp:137
XLContentType type() const
Definition XLContentTypes.cpp:153
friend class XLContentTypes
Definition XLContentTypes.hpp:81
XLContentItem & operator=(XLContentItem &&other) noexcept
std::string path() const
Definition XLContentTypes.cpp:155
XLContentTypes & operator=(XLContentTypes &&other) noexcept
void addDefault(std::string_view extension, std::string_view contentType)
Add a new default extension key/value pair to the data store.
Definition XLContentTypes.cpp:186
std::vector< XLContentItem > getContentItems()
Definition XLContentTypes.cpp:277
void deleteDefault(std::string_view extension)
Delete a default extension from the content types.
Definition XLContentTypes.cpp:265
void deleteOverride(std::string_view path)
Definition XLContentTypes.cpp:257
bool hasDefault(std::string_view extension) const
Check if a default extension exists.
Definition XLContentTypes.cpp:169
XLContentItem contentItem(std::string_view path)
Definition XLContentTypes.cpp:274
XLContentTypes(XLContentTypes &&other) noexcept
bool hasOverride(std::string_view path) const
Check if an override exists.
Definition XLContentTypes.cpp:172
void addOverride(std::string_view path, XLContentType type)
Add a new override key/getValue pair to the data store.
Definition XLContentTypes.cpp:209
XLContentTypes(const XLContentTypes &other)
void updateOverride(std::string_view path, XLContentType type)
Update an existing override key/getValue pair or add if it does not exist.
Definition XLContentTypes.cpp:237
XLContentTypes & operator=(const XLContentTypes &other)
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
std::string XLContentTypeToString(XLContentType type)
utility function: determine the name of an XLContentType value
XLContentType
Definition XLContentTypes.hpp:38
@ Workbook
Definition XLContentTypes.hpp:39
@ Slicer
Definition XLContentTypes.hpp:64
@ Chart
Definition XLContentTypes.hpp:49
@ ControlProperties
Definition XLContentTypes.hpp:52
@ CoreProperties
Definition XLContentTypes.hpp:55
@ SharedStrings
Definition XLContentTypes.hpp:47
@ ChartColorStyle
Definition XLContentTypes.hpp:51
@ Styles
Definition XLContentTypes.hpp:46
@ Table
Definition XLContentTypes.hpp:59
@ Worksheet
Definition XLContentTypes.hpp:42
@ ExternalLink
Definition XLContentTypes.hpp:44
@ VBAProject
Definition XLContentTypes.hpp:54
@ PivotCacheDefinition
Definition XLContentTypes.hpp:66
@ Drawing
Definition XLContentTypes.hpp:48
@ PivotCacheRecords
Definition XLContentTypes.hpp:67
@ PivotTable
Definition XLContentTypes.hpp:63
@ CalculationChain
Definition XLContentTypes.hpp:53
@ Hyperlink
Definition XLContentTypes.hpp:61
@ Comments
Definition XLContentTypes.hpp:58
@ Unknown
Definition XLContentTypes.hpp:62
@ SlicerCache
Definition XLContentTypes.hpp:65
@ ExtendedProperties
Definition XLContentTypes.hpp:56
@ Persons
Definition XLContentTypes.hpp:69
@ WorkbookMacroEnabled
Definition XLContentTypes.hpp:41
@ ChartStyle
Definition XLContentTypes.hpp:50
@ Theme
Definition XLContentTypes.hpp:45
@ CustomProperties
Definition XLContentTypes.hpp:57
@ Relationships
Definition XLContentTypes.hpp:40
@ Chartsheet
Definition XLContentTypes.hpp:43
@ VMLDrawing
Definition XLContentTypes.hpp:60
@ ThreadedComments
Definition XLContentTypes.hpp:68
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64