OpenXLSX 1.10.0
Loading...
Searching...
No Matches
XLTables.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLTABLES_HPP
2#define OPENXLSX_XLTABLES_HPP
3
4// ===== External Includes ===== //
5#include <cstdint> // uint8_t, uint16_t, uint32_t
6#include <ostream> // std::basic_ostream
7#include <string>
8#include <string_view>
9#include <vector>
10
11// ===== OpenXLSX Includes ===== //
12#include "OpenXLSX-Exports.hpp"
13#include "XLAutoFilter.hpp"
14#include "XLException.hpp"
15#include "XLTableColumn.hpp"
16#include "XLXmlData.hpp"
17#include "XLXmlFile.hpp"
18
19namespace OpenXLSX
20{
21 class XLWorksheet;
22 class XLCellRange;
23
25 {
26 std::string name = ""; // Defaults to column name if empty
27 std::string caption = ""; // Defaults to column name if empty
28 uint32_t width = 144; // pixels
29 uint32_t height = 200; // pixels
30 int32_t offsetX = 0; // pixels
31 int32_t offsetY = 0; // pixels
32 std::string slicerStyle = ""; // Empty = use Excel default (no style attribute written)
33 std::vector<std::string> selectedItems = {};
34 };
35
36 class XLTable;
37
41 class OPENXLSX_EXPORT XLTableCollection
42 {
43 friend class XLWorksheet;
44
45 public:
49 XLTableCollection() = default;
50
56 explicit XLTableCollection(XMLNode node, XLWorksheet* worksheet);
57
61 size_t count() const;
62
66 XLTable operator[](size_t index) const;
67
71 XLTable table(std::string_view name) const;
72
79 XLTable add(std::string_view name, std::string_view range);
80
87 XLTable add(std::string_view name, const XLCellRange& range);
88
92 bool valid() const;
93
94 private:
95 XMLNode m_sheetNode;
96 XLWorksheet* m_worksheet{nullptr};
97 mutable std::vector<XLTable> m_tables;
98 mutable bool m_loaded{false};
99
100 void load() const;
101 };
102
106 class OPENXLSX_EXPORT XLTable : public XLXmlFile
107 {
108 friend class XLTableCollection;
109 friend class XLWorksheet;
110
111 public:
115 XLTable() : XLXmlFile(nullptr) {};
116
121 XLTable(XLXmlData* xmlData);
122
127 XLTable(const XLTable& other) = default;
128
132 XLTable(XLTable&& other) noexcept = default;
133
137 ~XLTable() = default;
138
142 XLTable& operator=(const XLTable&) = default;
143
147 XLTable& operator=(XLTable&& other) noexcept = default;
148
153 uint32_t id() const;
154
159 std::string name() const;
160
165 void setName(std::string_view name);
166
171 std::string displayName() const;
172
177 void setDisplayName(std::string_view name);
178
183 std::string rangeReference() const;
184
189 void setRangeReference(std::string_view ref);
190
195 std::string styleName() const;
196
201 void setStyleName(std::string_view styleName);
202
207 std::string comment() const;
208
213 void setComment(std::string_view comment);
214
219 uint32_t headerRowDxfId() const;
220
225 void setHeaderRowDxfId(uint32_t id);
226
231 uint32_t dataDxfId() const;
232
237 void setDataDxfId(uint32_t id);
238
243 bool published() const;
244
249 void setPublished(bool published);
250
255 bool showRowStripes() const;
256
261 void setShowRowStripes(bool show);
262
267 bool showHeaderRow() const;
268
273 void setShowHeaderRow(bool show);
274
279 bool showTotalsRow() const;
280
285 void setShowTotalsRow(bool show);
286
291 bool showColumnStripes() const;
292
297 void setShowColumnStripes(bool show);
298
303 bool showFirstColumn() const;
304
309 void setShowFirstColumn(bool show);
310
315 bool showLastColumn() const;
316
321 void setShowLastColumn(bool show);
322
328 XLTableColumn appendColumn(std::string_view name);
329
335 XLTableColumn column(std::string_view name) const;
336
342 XLTableColumn column(uint32_t id) const;
343
348 XLAutoFilter autoFilter() const;
349
354 void resizeToFitData(const XLWorksheet& worksheet);
355
360 void createColumnsFromRange(const XLWorksheet& worksheet);
361
365 void print(std::basic_ostream<char>& ostr) const;
366 };
367
368 // For compatibility
370} // namespace OpenXLSX
371
372#endif // OPENXLSX_XLTABLES_HPP
Definition XLXmlParser.hpp:84
Definition XLAutoFilter.hpp:90
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:30
The XLTableCollection class manages multiple tables within a worksheet.
Definition XLTables.hpp:42
XLTableCollection()=default
Constructor.
The XLTableColumn class encapsulates the <tableColumn> XML node. It allows setting different kinds of...
Definition XLTableColumn.hpp:21
The XLTable class represents a single Excel table (.xml file).
Definition XLTables.hpp:107
uint32_t headerRowDxfId() const
Get the differential formatting ID for the header row.
XLTable()
Constructor.
Definition XLTables.hpp:115
void setHeaderRowDxfId(uint32_t id)
Set the differential formatting ID for the header row.
uint32_t dataDxfId() const
Get the differential formatting ID for the data rows.
~XLTable()=default
The destructor.
XLTable(XLTable &&other) noexcept=default
Move constructor.
XLTable & operator=(const XLTable &)=default
Assignment operator.
XLTable & operator=(XLTable &&other) noexcept=default
Move assignment operator.
void setDataDxfId(uint32_t id)
Set the differential formatting ID for the data rows.
XLTable(const XLTable &other)=default
The copy constructor.
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:120
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
Definition XLTables.hpp:25
std::string slicerStyle
Definition XLTables.hpp:32
uint32_t width
Definition XLTables.hpp:28
int32_t offsetX
Definition XLTables.hpp:30
std::vector< std::string > selectedItems
Definition XLTables.hpp:33
uint32_t height
Definition XLTables.hpp:29
std::string caption
Definition XLTables.hpp:27
int32_t offsetY
Definition XLTables.hpp:31
std::string name
Definition XLTables.hpp:26