OpenXLSX 1.9.1
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 };
33
34 class XLTable;
35
39 class OPENXLSX_EXPORT XLTableCollection
40 {
41 friend class XLWorksheet;
42
43 public:
47 XLTableCollection() = default;
48
54 explicit XLTableCollection(XMLNode node, XLWorksheet* worksheet);
55
59 size_t count() const;
60
64 XLTable operator[](size_t index) const;
65
69 XLTable table(std::string_view name) const;
70
77 XLTable add(std::string_view name, std::string_view range);
78
85 XLTable add(std::string_view name, const XLCellRange& range);
86
90 bool valid() const;
91
92 private:
93 XMLNode m_sheetNode;
94 XLWorksheet* m_worksheet{nullptr};
95 mutable std::vector<XLTable> m_tables;
96 mutable bool m_loaded{false};
97
98 void load() const;
99 };
100
104 class OPENXLSX_EXPORT XLTable : public XLXmlFile
105 {
106 friend class XLTableCollection;
107 friend class XLWorksheet;
108
109 public:
113 XLTable() : XLXmlFile(nullptr) {};
114
120
125 XLTable(const XLTable& other) = default;
126
130 XLTable(XLTable&& other) noexcept = default;
131
135 ~XLTable() = default;
136
140 XLTable& operator=(const XLTable&) = default;
141
145 XLTable& operator=(XLTable&& other) noexcept = default;
146
151 uint32_t id() const;
152
157 std::string name() const;
158
163 void setName(std::string_view name);
164
169 std::string displayName() const;
170
175 void setDisplayName(std::string_view name);
176
181 std::string rangeReference() const;
182
187 void setRangeReference(std::string_view ref);
188
193 std::string styleName() const;
194
199 void setStyleName(std::string_view styleName);
200
205 std::string comment() const;
206
211 void setComment(std::string_view comment);
212
217 uint32_t headerRowDxfId() const;
218
223 void setHeaderRowDxfId(uint32_t id);
224
229 uint32_t dataDxfId() const;
230
235 void setDataDxfId(uint32_t id);
236
241 bool published() const;
242
247 void setPublished(bool published);
248
253 bool showRowStripes() const;
254
259 void setShowRowStripes(bool show);
260
265 bool showHeaderRow() const;
266
271 void setShowHeaderRow(bool show);
272
277 bool showTotalsRow() const;
278
283 void setShowTotalsRow(bool show);
284
289 bool showColumnStripes() const;
290
295 void setShowColumnStripes(bool show);
296
301 bool showFirstColumn() const;
302
307 void setShowFirstColumn(bool show);
308
313 bool showLastColumn() const;
314
319 void setShowLastColumn(bool show);
320
326 XLTableColumn appendColumn(std::string_view name);
327
333 XLTableColumn column(std::string_view name) const;
334
340 XLTableColumn column(uint32_t id) const;
341
346 XLAutoFilter autoFilter() const;
347
352 void resizeToFitData(const XLWorksheet& worksheet);
353
358 void createColumnsFromRange(const XLWorksheet& worksheet);
359
363 void print(std::basic_ostream<char>& ostr) const;
364 };
365
366 // For compatibility
368} // namespace OpenXLSX
369
370#endif // OPENXLSX_XLTABLES_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
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:40
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:105
uint32_t headerRowDxfId() const
Get the differential formatting ID for the header row.
XLTable()
Constructor.
Definition XLTables.hpp:113
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:118
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
Definition XLTables.hpp:25
uint32_t width
Definition XLTables.hpp:28
int32_t offsetX
Definition XLTables.hpp:30
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