OpenXLSX 1.10.0
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 std::vector<std::string> selectedItems;
21 };
22
23 class OPENXLSX_EXPORT XLPivotTableOptions
24 {
25 public:
32 XLPivotTableOptions(std::string name, std::string sourceRange, std::string targetCell)
33 : m_name(std::move(name)), m_sourceRange(std::move(sourceRange)), m_targetCell(std::move(targetCell)) {}
34
35 // --- Fluent Configuration Builders --- //
36
37 XLPivotTableOptions& addRowField(std::string fieldName, std::vector<std::string> selectedItems = {}) {
38 m_rows.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0, std::move(selectedItems)});
39 return *this;
40 }
41
42 XLPivotTableOptions& addColumnField(std::string fieldName, std::vector<std::string> selectedItems = {}) {
43 m_columns.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0, std::move(selectedItems)});
44 return *this;
45 }
46
47 XLPivotTableOptions& addDataField(std::string fieldName, std::string customName = "", XLPivotSubtotal subtotal = XLPivotSubtotal::Sum, uint32_t numFmtId = 0) {
48 m_data.push_back({std::move(fieldName), subtotal, std::move(customName), numFmtId, {}});
49 return *this;
50 }
51
52 XLPivotTableOptions& addFilterField(std::string fieldName, std::vector<std::string> selectedItems = {}) {
53 m_filters.push_back({std::move(fieldName), XLPivotSubtotal::Sum, "", 0, std::move(selectedItems)});
54 return *this;
55 }
56
57 XLPivotTableOptions& setPivotTableStyle(std::string styleName) { m_pivotTableStyleName = std::move(styleName); return *this; }
58 XLPivotTableOptions& setDataOnRows(bool value) { m_dataOnRows = value; return *this; }
59 XLPivotTableOptions& setRowGrandTotals(bool value) { m_rowGrandTotals = value; return *this; }
60 XLPivotTableOptions& setColGrandTotals(bool value) { m_colGrandTotals = value; return *this; }
61 XLPivotTableOptions& setShowDrill(bool value) { m_showDrill = value; return *this; }
62 XLPivotTableOptions& setUseAutoFormatting(bool value) { m_useAutoFormatting = value; return *this; }
63 XLPivotTableOptions& setPageOverThenDown(bool value) { m_pageOverThenDown = value; return *this; }
64 XLPivotTableOptions& setMergeItem(bool value) { m_mergeItem = value; return *this; }
65 XLPivotTableOptions& setCompactData(bool value) { m_compactData = value; return *this; }
66 XLPivotTableOptions& setShowError(bool value) { m_showError = value; return *this; }
67 XLPivotTableOptions& setShowRowHeaders(bool value) { m_showRowHeaders = value; return *this; }
68 XLPivotTableOptions& setShowColHeaders(bool value) { m_showColHeaders = value; return *this; }
69 XLPivotTableOptions& setShowRowStripes(bool value) { m_showRowStripes = value; return *this; }
70 XLPivotTableOptions& setShowColStripes(bool value) { m_showColStripes = value; return *this; }
71 XLPivotTableOptions& setShowLastColumn(bool value) { m_showLastColumn = value; return *this; }
72
73 XLPivotTableOptions& setClassicLayout(bool value) { m_classicLayout = value; return *this; }
74 XLPivotTableOptions& setFieldPrintTitles(bool value) { m_fieldPrintTitles = value; return *this; }
75 XLPivotTableOptions& setItemPrintTitles(bool value) { m_itemPrintTitles = value; return *this; }
76
77 // --- Getters --- //
78 [[nodiscard]] const std::string& name() const { return m_name; }
79 [[nodiscard]] const std::string& sourceRange() const { return m_sourceRange; }
80 [[nodiscard]] const std::string& targetCell() const { return m_targetCell; }
81 [[nodiscard]] const std::vector<XLPivotField>& rows() const { return m_rows; }
82 [[nodiscard]] const std::vector<XLPivotField>& columns() const { return m_columns; }
83 [[nodiscard]] const std::vector<XLPivotField>& data() const { return m_data; }
84 [[nodiscard]] const std::vector<XLPivotField>& filters() const { return m_filters; }
85 [[nodiscard]] const std::string& pivotTableStyleName() const { return m_pivotTableStyleName; }
86
87 [[nodiscard]] bool dataOnRows() const { return m_dataOnRows; }
88 [[nodiscard]] bool rowGrandTotals() const { return m_rowGrandTotals; }
89 [[nodiscard]] bool colGrandTotals() const { return m_colGrandTotals; }
90 [[nodiscard]] bool showDrill() const { return m_showDrill; }
91 [[nodiscard]] bool useAutoFormatting() const { return m_useAutoFormatting; }
92 [[nodiscard]] bool pageOverThenDown() const { return m_pageOverThenDown; }
93 [[nodiscard]] bool mergeItem() const { return m_mergeItem; }
94 [[nodiscard]] bool compactData() const { return m_compactData; }
95 [[nodiscard]] bool showError() const { return m_showError; }
96 [[nodiscard]] bool showRowHeaders() const { return m_showRowHeaders; }
97 [[nodiscard]] bool showColHeaders() const { return m_showColHeaders; }
98 [[nodiscard]] bool showRowStripes() const { return m_showRowStripes; }
99 [[nodiscard]] bool showColStripes() const { return m_showColStripes; }
100 [[nodiscard]] bool showLastColumn() const { return m_showLastColumn; }
101
102 [[nodiscard]] bool classicLayout() const { return m_classicLayout; }
103 [[nodiscard]] bool fieldPrintTitles() const { return m_fieldPrintTitles; }
104 [[nodiscard]] bool itemPrintTitles() const { return m_itemPrintTitles; }
105
106 private:
107 std::string m_name;
108 std::string m_sourceRange;
109 std::string m_targetCell;
110
111 std::vector<XLPivotField> m_rows;
112 std::vector<XLPivotField> m_columns;
113 std::vector<XLPivotField> m_data;
114 std::vector<XLPivotField> m_filters;
115
116 bool m_dataOnRows {false};
117 bool m_rowGrandTotals {true};
118 bool m_colGrandTotals {true};
119 bool m_showDrill {true};
120 bool m_useAutoFormatting {false};
121 bool m_pageOverThenDown {false};
122 bool m_mergeItem {false};
123 bool m_compactData {true};
124 bool m_showError {false};
125 bool m_showRowHeaders {true};
126 bool m_showColHeaders {true};
127 bool m_showRowStripes {false};
128 bool m_showColStripes {false};
129 bool m_showLastColumn {false};
130
131 bool m_classicLayout {false};
132 bool m_fieldPrintTitles {false};
133 bool m_itemPrintTitles {false};
134
135 std::string m_pivotTableStyleName{"PivotStyleLight16"};
136 };
137
138 class OPENXLSX_EXPORT XLPivotTable final : public XLXmlFile
139 {
140 public:
141 class XLRelationships relationships();
142
143 XLPivotTable() : XLXmlFile(nullptr) {}
144 explicit XLPivotTable(XLXmlData* xmlData);
145 ~XLPivotTable() = default;
146 XLPivotTable(const XLPivotTable& other) = default;
147 XLPivotTable(XLPivotTable&& other) noexcept = default;
148 XLPivotTable& operator=(const XLPivotTable& other) = default;
149 XLPivotTable& operator=(XLPivotTable&& other) noexcept = default;
150
151 void setName(std::string_view name);
152
156 void setRefreshOnLoad(bool refresh = true);
157
161 std::string name() const;
162
166 std::string targetCell() const;
167
171 std::string sourceRange() const;
172
176 class XLPivotCacheDefinition cacheDefinition() const;
177
182 void changeSourceRange(std::string_view newRange);
183 };
184
185 class OPENXLSX_EXPORT XLPivotCacheDefinition final : public XLXmlFile
186 {
187 public:
188 class XLRelationships relationships();
189
191 explicit XLPivotCacheDefinition(XLXmlData* xmlData);
197
201 std::string sourceRange() const;
202
207 void changeSourceRange(std::string_view newRange);
208 };
209
210 class OPENXLSX_EXPORT XLPivotCacheRecords final : public XLXmlFile
211 {
212 public:
214 explicit XLPivotCacheRecords(XLXmlData* xmlData);
217 XLPivotCacheRecords(XLPivotCacheRecords&& other) noexcept = default;
220 };
221} // namespace OpenXLSX
222
223#endif // OPENXLSX_XLPIVOTTABLE_HPP
Definition XLPivotTable.hpp:186
XLPivotCacheDefinition(XLPivotCacheDefinition &&other) noexcept=default
XLPivotCacheDefinition()
Definition XLPivotTable.hpp:190
XLPivotCacheDefinition & operator=(const XLPivotCacheDefinition &other)=default
XLPivotCacheDefinition & operator=(XLPivotCacheDefinition &&other) noexcept=default
XLPivotCacheDefinition(const XLPivotCacheDefinition &other)=default
Definition XLPivotTable.hpp:211
XLPivotCacheRecords & operator=(const XLPivotCacheRecords &other)=default
XLPivotCacheRecords()
Definition XLPivotTable.hpp:213
XLPivotCacheRecords & operator=(XLPivotCacheRecords &&other) noexcept=default
XLPivotCacheRecords(const XLPivotCacheRecords &other)=default
XLPivotCacheRecords(XLPivotCacheRecords &&other) noexcept=default
Definition XLPivotTable.hpp:24
bool dataOnRows() const
Definition XLPivotTable.hpp:87
XLPivotTableOptions & setFieldPrintTitles(bool value)
Definition XLPivotTable.hpp:74
XLPivotTableOptions & setShowRowStripes(bool value)
Definition XLPivotTable.hpp:69
XLPivotTableOptions & setRowGrandTotals(bool value)
Definition XLPivotTable.hpp:59
bool showColStripes() const
Definition XLPivotTable.hpp:99
const std::string & targetCell() const
Definition XLPivotTable.hpp:80
XLPivotTableOptions & setUseAutoFormatting(bool value)
Definition XLPivotTable.hpp:62
XLPivotTableOptions & addDataField(std::string fieldName, std::string customName="", XLPivotSubtotal subtotal=XLPivotSubtotal::Sum, uint32_t numFmtId=0)
Definition XLPivotTable.hpp:47
XLPivotTableOptions & setItemPrintTitles(bool value)
Definition XLPivotTable.hpp:75
bool useAutoFormatting() const
Definition XLPivotTable.hpp:91
XLPivotTableOptions & addFilterField(std::string fieldName, std::vector< std::string > selectedItems={})
Definition XLPivotTable.hpp:52
XLPivotTableOptions & setColGrandTotals(bool value)
Definition XLPivotTable.hpp:60
bool showRowHeaders() const
Definition XLPivotTable.hpp:96
bool classicLayout() const
Definition XLPivotTable.hpp:102
const std::string & pivotTableStyleName() const
Definition XLPivotTable.hpp:85
bool fieldPrintTitles() const
Definition XLPivotTable.hpp:103
XLPivotTableOptions & setShowLastColumn(bool value)
Definition XLPivotTable.hpp:71
const std::string & name() const
Definition XLPivotTable.hpp:78
bool showDrill() const
Definition XLPivotTable.hpp:90
XLPivotTableOptions & setCompactData(bool value)
Definition XLPivotTable.hpp:65
const std::vector< XLPivotField > & columns() const
Definition XLPivotTable.hpp:82
bool showLastColumn() const
Definition XLPivotTable.hpp:100
const std::string & sourceRange() const
Definition XLPivotTable.hpp:79
XLPivotTableOptions & setClassicLayout(bool value)
Definition XLPivotTable.hpp:73
XLPivotTableOptions & setPageOverThenDown(bool value)
Definition XLPivotTable.hpp:63
XLPivotTableOptions & setMergeItem(bool value)
Definition XLPivotTable.hpp:64
bool compactData() const
Definition XLPivotTable.hpp:94
const std::vector< XLPivotField > & data() const
Definition XLPivotTable.hpp:83
XLPivotTableOptions & setShowRowHeaders(bool value)
Definition XLPivotTable.hpp:67
bool pageOverThenDown() const
Definition XLPivotTable.hpp:92
bool showColHeaders() const
Definition XLPivotTable.hpp:97
XLPivotTableOptions & setShowColHeaders(bool value)
Definition XLPivotTable.hpp:68
XLPivotTableOptions & setShowError(bool value)
Definition XLPivotTable.hpp:66
const std::vector< XLPivotField > & filters() const
Definition XLPivotTable.hpp:84
XLPivotTableOptions & setShowColStripes(bool value)
Definition XLPivotTable.hpp:70
XLPivotTableOptions & setShowDrill(bool value)
Definition XLPivotTable.hpp:61
XLPivotTableOptions & addRowField(std::string fieldName, std::vector< std::string > selectedItems={})
Definition XLPivotTable.hpp:37
XLPivotTableOptions & setDataOnRows(bool value)
Definition XLPivotTable.hpp:58
XLPivotTableOptions & setPivotTableStyle(std::string styleName)
Definition XLPivotTable.hpp:57
bool showError() const
Definition XLPivotTable.hpp:95
XLPivotTableOptions(std::string name, std::string sourceRange, std::string targetCell)
Construct fully initialized Pivot Table options.
Definition XLPivotTable.hpp:32
XLPivotTableOptions & addColumnField(std::string fieldName, std::vector< std::string > selectedItems={})
Definition XLPivotTable.hpp:42
bool itemPrintTitles() const
Definition XLPivotTable.hpp:104
bool rowGrandTotals() const
Definition XLPivotTable.hpp:88
bool showRowStripes() const
Definition XLPivotTable.hpp:98
bool colGrandTotals() const
Definition XLPivotTable.hpp:89
bool mergeItem() const
Definition XLPivotTable.hpp:93
const std::vector< XLPivotField > & rows() const
Definition XLPivotTable.hpp:81
Definition XLPivotTable.hpp:139
XLPivotTable()
Definition XLPivotTable.hpp:143
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:68
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::vector< std::string > selectedItems
Definition XLPivotTable.hpp:20
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