OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLPivotTable.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLPIVOTTABLE_HPP
2#define OPENXLSX_XLPIVOTTABLE_HPP
3
4#include "OpenXLSX-Exports.hpp"
5#include "XLXmlFile.hpp"
6#include <string>
7#include <string_view>
8#include <vector>
9
10namespace OpenXLSX
11{
13
15 {
16 std::string name;
18 std::string customName;
19 uint32_t numFmtId = 0; // Number format ID (e.g., 3 for '#,##0', 4 for '#,##0.00', 9 for '0%')
20 };
21
22 class OPENXLSX_EXPORT XLPivotTableOptions
23 {
24 public:
31 XLPivotTableOptions(std::string name, std::string sourceRange, std::string targetCell)
32 : m_name(std::move(name)), m_sourceRange(std::move(sourceRange)), m_targetCell(std::move(targetCell)) {}
33
34 // --- Fluent Configuration Builders --- //
35
36 XLPivotTableOptions& addRowField(std::string fieldName) {
37 m_rows.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0});
38 return *this;
39 }
40
41 XLPivotTableOptions& addColumnField(std::string fieldName) {
42 m_columns.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0});
43 return *this;
44 }
45
46 XLPivotTableOptions& addDataField(std::string fieldName, std::string customName = "", XLPivotSubtotal subtotal = XLPivotSubtotal::Sum, uint32_t numFmtId = 0) {
47 m_data.push_back({std::move(fieldName), subtotal, std::move(customName), numFmtId});
48 return *this;
49 }
50
51 XLPivotTableOptions& addFilterField(std::string fieldName) {
52 m_filters.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0});
53 return *this;
54 }
55
56 XLPivotTableOptions& setPivotTableStyle(std::string styleName) { m_pivotTableStyleName = std::move(styleName); return *this; }
57 XLPivotTableOptions& setDataOnRows(bool value) { m_dataOnRows = value; return *this; }
58 XLPivotTableOptions& setRowGrandTotals(bool value) { m_rowGrandTotals = value; return *this; }
59 XLPivotTableOptions& setColGrandTotals(bool value) { m_colGrandTotals = value; return *this; }
60 XLPivotTableOptions& setShowDrill(bool value) { m_showDrill = value; return *this; }
61 XLPivotTableOptions& setUseAutoFormatting(bool value) { m_useAutoFormatting = value; return *this; }
62 XLPivotTableOptions& setPageOverThenDown(bool value) { m_pageOverThenDown = value; return *this; }
63 XLPivotTableOptions& setMergeItem(bool value) { m_mergeItem = value; return *this; }
64 XLPivotTableOptions& setCompactData(bool value) { m_compactData = value; return *this; }
65 XLPivotTableOptions& setShowError(bool value) { m_showError = value; return *this; }
66 XLPivotTableOptions& setShowRowHeaders(bool value) { m_showRowHeaders = value; return *this; }
67 XLPivotTableOptions& setShowColHeaders(bool value) { m_showColHeaders = value; return *this; }
68 XLPivotTableOptions& setShowRowStripes(bool value) { m_showRowStripes = value; return *this; }
69 XLPivotTableOptions& setShowColStripes(bool value) { m_showColStripes = value; return *this; }
70 XLPivotTableOptions& setShowLastColumn(bool value) { m_showLastColumn = value; return *this; }
71
72 // --- Getters --- //
73 [[nodiscard]] const std::string& name() const { return m_name; }
74 [[nodiscard]] const std::string& sourceRange() const { return m_sourceRange; }
75 [[nodiscard]] const std::string& targetCell() const { return m_targetCell; }
76 [[nodiscard]] const std::vector<XLPivotField>& rows() const { return m_rows; }
77 [[nodiscard]] const std::vector<XLPivotField>& columns() const { return m_columns; }
78 [[nodiscard]] const std::vector<XLPivotField>& data() const { return m_data; }
79 [[nodiscard]] const std::vector<XLPivotField>& filters() const { return m_filters; }
80 [[nodiscard]] const std::string& pivotTableStyleName() const { return m_pivotTableStyleName; }
81
82 [[nodiscard]] bool dataOnRows() const { return m_dataOnRows; }
83 [[nodiscard]] bool rowGrandTotals() const { return m_rowGrandTotals; }
84 [[nodiscard]] bool colGrandTotals() const { return m_colGrandTotals; }
85 [[nodiscard]] bool showDrill() const { return m_showDrill; }
86 [[nodiscard]] bool useAutoFormatting() const { return m_useAutoFormatting; }
87 [[nodiscard]] bool pageOverThenDown() const { return m_pageOverThenDown; }
88 [[nodiscard]] bool mergeItem() const { return m_mergeItem; }
89 [[nodiscard]] bool compactData() const { return m_compactData; }
90 [[nodiscard]] bool showError() const { return m_showError; }
91 [[nodiscard]] bool showRowHeaders() const { return m_showRowHeaders; }
92 [[nodiscard]] bool showColHeaders() const { return m_showColHeaders; }
93 [[nodiscard]] bool showRowStripes() const { return m_showRowStripes; }
94 [[nodiscard]] bool showColStripes() const { return m_showColStripes; }
95 [[nodiscard]] bool showLastColumn() const { return m_showLastColumn; }
96
97 private:
98 std::string m_name;
99 std::string m_sourceRange;
100 std::string m_targetCell;
101
102 std::vector<XLPivotField> m_rows;
103 std::vector<XLPivotField> m_columns;
104 std::vector<XLPivotField> m_data;
105 std::vector<XLPivotField> m_filters;
106
107 bool m_dataOnRows {false};
108 bool m_rowGrandTotals {true};
109 bool m_colGrandTotals {true};
110 bool m_showDrill {true};
111 bool m_useAutoFormatting {false};
112 bool m_pageOverThenDown {false};
113 bool m_mergeItem {false};
114 bool m_compactData {true};
115 bool m_showError {false};
116 bool m_showRowHeaders {true};
117 bool m_showColHeaders {true};
118 bool m_showRowStripes {false};
119 bool m_showColStripes {false};
120 bool m_showLastColumn {false};
121
122 std::string m_pivotTableStyleName{"PivotStyleLight16"};
123 };
124
125 class OPENXLSX_EXPORT XLPivotTable final : public XLXmlFile
126 {
127 public:
128 class XLRelationships relationships();
129
130 XLPivotTable() : XLXmlFile(nullptr) {}
131 explicit XLPivotTable(XLXmlData* xmlData);
132 ~XLPivotTable() = default;
133 XLPivotTable(const XLPivotTable& other) = default;
134 XLPivotTable(XLPivotTable&& other) noexcept = default;
135 XLPivotTable& operator=(const XLPivotTable& other) = default;
136 XLPivotTable& operator=(XLPivotTable&& other) noexcept = default;
137
138 void setName(std::string_view name);
139
143 void setRefreshOnLoad(bool refresh = true);
144
148 std::string name() const;
149
153 std::string targetCell() const;
154
158 std::string sourceRange() const;
159
163 class XLPivotCacheDefinition cacheDefinition() const;
164
169 void changeSourceRange(std::string_view newRange);
170 };
171
172 class OPENXLSX_EXPORT XLPivotCacheDefinition final : public XLXmlFile
173 {
174 public:
175 class XLRelationships relationships();
176
184
188 std::string sourceRange() const;
189
194 void changeSourceRange(std::string_view newRange);
195 };
196
197 class OPENXLSX_EXPORT XLPivotCacheRecords final : public XLXmlFile
198 {
199 public:
204 XLPivotCacheRecords(XLPivotCacheRecords&& other) noexcept = default;
207 };
208} // namespace OpenXLSX
209
210#endif // OPENXLSX_XLPIVOTTABLE_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
Definition XLPivotTable.hpp:173
XLPivotCacheDefinition(XLPivotCacheDefinition &&other) noexcept=default
XLPivotCacheDefinition()
Definition XLPivotTable.hpp:177
XLPivotCacheDefinition & operator=(const XLPivotCacheDefinition &other)=default
XLPivotCacheDefinition & operator=(XLPivotCacheDefinition &&other) noexcept=default
XLPivotCacheDefinition(const XLPivotCacheDefinition &other)=default
Definition XLPivotTable.hpp:198
XLPivotCacheRecords & operator=(const XLPivotCacheRecords &other)=default
XLPivotCacheRecords()
Definition XLPivotTable.hpp:200
XLPivotCacheRecords & operator=(XLPivotCacheRecords &&other) noexcept=default
XLPivotCacheRecords(const XLPivotCacheRecords &other)=default
XLPivotCacheRecords(XLPivotCacheRecords &&other) noexcept=default
Definition XLPivotTable.hpp:23
bool dataOnRows() const
Definition XLPivotTable.hpp:82
XLPivotTableOptions & setShowRowStripes(bool value)
Definition XLPivotTable.hpp:68
XLPivotTableOptions & setRowGrandTotals(bool value)
Definition XLPivotTable.hpp:58
bool showColStripes() const
Definition XLPivotTable.hpp:94
const std::string & targetCell() const
Definition XLPivotTable.hpp:75
XLPivotTableOptions & setUseAutoFormatting(bool value)
Definition XLPivotTable.hpp:61
XLPivotTableOptions & addDataField(std::string fieldName, std::string customName="", XLPivotSubtotal subtotal=XLPivotSubtotal::Sum, uint32_t numFmtId=0)
Definition XLPivotTable.hpp:46
bool useAutoFormatting() const
Definition XLPivotTable.hpp:86
XLPivotTableOptions & setColGrandTotals(bool value)
Definition XLPivotTable.hpp:59
bool showRowHeaders() const
Definition XLPivotTable.hpp:91
const std::string & pivotTableStyleName() const
Definition XLPivotTable.hpp:80
XLPivotTableOptions & setShowLastColumn(bool value)
Definition XLPivotTable.hpp:70
const std::string & name() const
Definition XLPivotTable.hpp:73
bool showDrill() const
Definition XLPivotTable.hpp:85
XLPivotTableOptions & setCompactData(bool value)
Definition XLPivotTable.hpp:64
const std::vector< XLPivotField > & columns() const
Definition XLPivotTable.hpp:77
bool showLastColumn() const
Definition XLPivotTable.hpp:95
const std::string & sourceRange() const
Definition XLPivotTable.hpp:74
XLPivotTableOptions & setPageOverThenDown(bool value)
Definition XLPivotTable.hpp:62
XLPivotTableOptions & setMergeItem(bool value)
Definition XLPivotTable.hpp:63
bool compactData() const
Definition XLPivotTable.hpp:89
const std::vector< XLPivotField > & data() const
Definition XLPivotTable.hpp:78
XLPivotTableOptions & setShowRowHeaders(bool value)
Definition XLPivotTable.hpp:66
XLPivotTableOptions & addFilterField(std::string fieldName)
Definition XLPivotTable.hpp:51
bool pageOverThenDown() const
Definition XLPivotTable.hpp:87
bool showColHeaders() const
Definition XLPivotTable.hpp:92
XLPivotTableOptions & setShowColHeaders(bool value)
Definition XLPivotTable.hpp:67
XLPivotTableOptions & setShowError(bool value)
Definition XLPivotTable.hpp:65
const std::vector< XLPivotField > & filters() const
Definition XLPivotTable.hpp:79
XLPivotTableOptions & setShowColStripes(bool value)
Definition XLPivotTable.hpp:69
XLPivotTableOptions & setShowDrill(bool value)
Definition XLPivotTable.hpp:60
XLPivotTableOptions & setDataOnRows(bool value)
Definition XLPivotTable.hpp:57
XLPivotTableOptions & setPivotTableStyle(std::string styleName)
Definition XLPivotTable.hpp:56
bool showError() const
Definition XLPivotTable.hpp:90
XLPivotTableOptions & addRowField(std::string fieldName)
Definition XLPivotTable.hpp:36
XLPivotTableOptions & addColumnField(std::string fieldName)
Definition XLPivotTable.hpp:41
XLPivotTableOptions(std::string name, std::string sourceRange, std::string targetCell)
Construct fully initialized Pivot Table options.
Definition XLPivotTable.hpp:31
bool rowGrandTotals() const
Definition XLPivotTable.hpp:83
bool showRowStripes() const
Definition XLPivotTable.hpp:93
bool colGrandTotals() const
Definition XLPivotTable.hpp:84
bool mergeItem() const
Definition XLPivotTable.hpp:88
const std::vector< XLPivotField > & rows() const
Definition XLPivotTable.hpp:76
Definition XLPivotTable.hpp:126
XLPivotTable()
Definition XLPivotTable.hpp:130
XLPivotTable(const XLPivotTable &other)=default
XLPivotTable(XLPivotTable &&other) noexcept=default
XLPivotTable & operator=(const XLPivotTable &other)=default
XLPivotTable & operator=(XLPivotTable &&other) noexcept=default
Definition XLRelationships.hpp:140
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:29
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition IZipArchive.hpp:18
XLPivotSubtotal
Definition XLPivotTable.hpp:12
Definition XLCellIterator.hpp:121
Definition XLPivotTable.hpp:15
std::string customName
Definition XLPivotTable.hpp:18
std::string name
Definition XLPivotTable.hpp:16
XLPivotSubtotal subtotal
Definition XLPivotTable.hpp:17
uint32_t numFmtId
Definition XLPivotTable.hpp:19