OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLRow.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_XLROW_HPP
12#define OPENXLSX_XLROW_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// ===== OpenXLSX Includes ===== //
21#include "OpenXLSX-Exports.hpp"
22#include "XLRowData.hpp"
23#include "XLXmlSchema.hpp"
24
25namespace OpenXLSX
26{
27 class XLRowRange;
28
33 class OPENXLSX_EXPORT XLRow
34 {
35 friend class XLRowIterator;
36 friend class XLRowDataProxy;
37 friend bool operator==(const XLRow& lhs, const XLRow& rhs);
38 friend bool operator!=(const XLRow& lhs, const XLRow& rhs);
39 friend bool operator<(const XLRow& lhs, const XLRow& rhs);
40 friend bool operator>(const XLRow& lhs, const XLRow& rhs);
41 friend bool operator<=(const XLRow& lhs, const XLRow& rhs);
42 friend bool operator>=(const XLRow& lhs, const XLRow& rhs);
43
44 //---------- PUBLIC MEMBER FUNCTIONS ----------//
45 public:
49 XLRow();
50
56 XLRow(const XMLNode& rowNode, const XLSharedStrings& sharedStrings, XLWorksheet* wks = nullptr);
57
62 XLRow(const XLRow& other);
63
68 XLRow(XLRow&& other) noexcept;
69
75
80 XLRow& operator=(const XLRow& other);
81
86 XLRow& operator=(XLRow&& other) noexcept;
87
92 bool empty() const;
93
98 explicit operator bool() const;
99
104 double height() const;
105
110 void setHeight(float height);
111
117 float descent() const;
118
124 void setDescent(float descent);
125
130 bool isHidden() const;
131
136 void setHidden(bool state);
137
142 uint8_t outlineLevel() const;
143
148 void setOutlineLevel(uint8_t level);
149
153 [[nodiscard]] XLRowProperties properties() const;
154
158 void setProperties(const XLRowProperties& props);
159
164 bool isCollapsed() const;
165
170 void setCollapsed(bool state);
171
176 uint32_t rowNumber() const;
177
182 uint16_t cellCount() const;
183
189
194 const XLRowDataProxy& values() const;
195
201 template<typename T>
202 T values() const
203 { return static_cast<T>(values()); }
204
209 XLRowDataRange cells() const;
210
216 XLRowDataRange cells(uint16_t cellCount) const;
217
224 XLRowDataRange cells(uint16_t firstCell, uint16_t lastCell) const;
225
231 XLCell findCell(uint16_t columNumber);
232
238 XLStyleIndex format() const;
239
245 bool setFormat(XLStyleIndex cellFormatIndex);
246
247 private:
254 static bool isEqual(const XLRow& lhs, const XLRow& rhs);
255
262 static bool isLessThan(const XLRow& lhs, const XLRow& rhs);
263
264 //---------- PRIVATE MEMBER VARIABLES ----------//
265 std::unique_ptr<XMLNode> m_rowNode;
266 XLSharedStringsRef m_sharedStrings;
267 XLRowDataProxy m_rowDataProxy;
268 XLWorksheet* m_wks{nullptr};
269 };
270
274 class OPENXLSX_EXPORT XLRowIterator
275 {
276 public:
277 using iterator_category = std::forward_iterator_tag;
279 using difference_type = int64_t;
280 using pointer = XLRow*;
281 using reference = XLRow&;
282
288 explicit XLRowIterator(const XLRowRange& rowRange, XLIteratorLocation loc);
289
294
299 XLRowIterator(const XLRowIterator& other);
300
305 XLRowIterator(XLRowIterator&& other) noexcept;
306
313
320
321 private
322 : // ===== Switch to private method that is used by the XLRowIterator increment operator++ and the dereference operators * and ->
323 static constexpr const bool XLCreateIfMissing = true; // code readability for updateCurrentRow parameter createIfMissing
324 static constexpr const bool XLDoNotCreateIfMissing = false; // "
329 void updateCurrentRow(bool createIfMissing);
330
331 public: // ===== Switch back to public methods
337
342 XLRowIterator operator++(int); // NOLINT
343
349
355
361 bool operator==(const XLRowIterator& rhs) const;
362
368 bool operator!=(const XLRowIterator& rhs) const;
369
374 explicit operator bool() const;
375
380 bool rowExists();
381
386 bool endReached() const { return m_endReached; }
387
392 uint32_t rowNumber() const { return m_endReached ? m_lastRow + 1 : m_currentRowNumber; }
393
394 private:
395 std::unique_ptr<XMLNode> m_dataNode;
396 uint32_t m_firstRow{1};
397 uint32_t m_lastRow{1};
398 XLRow m_currentRow;
399 XLSharedStringsRef m_sharedStrings;
400
401 // helper variables for non-creating iterator functionality
402 bool m_endReached;
403 XMLNode m_hintRow;
404 uint32_t m_hintRowNumber;
405 static constexpr const int XLNotLoaded = 0; // code readability for m_currentRowStatus
406 static constexpr const int XLNoSuchRow = 1; // "
407 static constexpr const int XLLoaded = 2; // "
408 int m_currentRowStatus;
409 uint32_t m_currentRowNumber;
410 };
411
415 class OPENXLSX_EXPORT XLRowRange
416 {
417 friend class XLRowIterator;
418
419 //----------------------------------------------------------------------------------------------------------------------
420 // Public Member Functions
421 //----------------------------------------------------------------------------------------------------------------------
422
423 public:
431 explicit XLRowRange(const XMLNode& dataNode, uint32_t first, uint32_t last, const XLSharedStrings& sharedStrings);
432
437 XLRowRange(const XLRowRange& other);
438
443 XLRowRange(XLRowRange&& other) noexcept;
444
449
455 XLRowRange& operator=(const XLRowRange& other);
456
462 XLRowRange& operator=(XLRowRange&& other) noexcept;
463
468 uint32_t rowCount() const;
469
475
481
482 //----------------------------------------------------------------------------------------------------------------------
483 // Private Member Variables
484 //----------------------------------------------------------------------------------------------------------------------
485
486 private:
487 std::unique_ptr<XMLNode> m_dataNode;
488 uint32_t m_firstRow;
489 uint32_t m_lastRow;
490 XLSharedStringsRef m_sharedStrings;
491 };
492
493} // namespace OpenXLSX
494
495namespace OpenXLSX
496{
503 inline bool operator==(const XLRow& lhs, const XLRow& rhs) { return XLRow::isEqual(lhs, rhs); }
504
511 inline bool operator!=(const XLRow& lhs, const XLRow& rhs) { return !(lhs.m_rowNode == rhs.m_rowNode); }
512
519 inline bool operator<(const XLRow& lhs, const XLRow& rhs) { return XLRow::isLessThan(lhs, rhs); }
520
527 inline bool operator>(const XLRow& lhs, const XLRow& rhs) { return (rhs < lhs); }
528
535 inline bool operator<=(const XLRow& lhs, const XLRow& rhs) { return !(lhs > rhs); }
536
543 inline bool operator>=(const XLRow& lhs, const XLRow& rhs) { return !(lhs < rhs); }
544
545} // namespace OpenXLSX
546
547#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
548# pragma warning(pop)
549#endif // _MSC_VER
550
551#endif // OPENXLSX_XLROW_HPP
An implementation class encapsulating the properties and behaviours of a spreadsheet cell.
Definition XLCell.hpp:51
The XLRowDataProxy is used as a proxy object when getting or setting row data. The class facilitates ...
Definition XLRowData.hpp:241
This class encapsulates the concept of a contiguous range of cells in a row.
Definition XLRowData.hpp:141
std::forward_iterator_tag iterator_category
Definition XLRow.hpp:277
reference operator*()
Definition XLRow.cpp:454
XLRow & reference
Definition XLRow.hpp:281
XLRowIterator & operator=(XLRowIterator &&other) noexcept
pointer operator->()
Definition XLRow.cpp:460
XLRow value_type
Definition XLRow.hpp:278
XLRow * pointer
Definition XLRow.hpp:280
XLRowIterator & operator++()
Definition XLRow.cpp:433
bool rowExists()
determine whether the row that the iterator points to exists (m_currentRowNumber)
Definition XLRow.cpp:486
uint32_t rowNumber() const
get the row number corresponding to the current iterator position
Definition XLRow.hpp:392
XLRowIterator & operator=(const XLRowIterator &other)
Definition XLRow.cpp:361
XLRowIterator(XLRowIterator &&other) noexcept
bool operator!=(const XLRowIterator &rhs) const
Definition XLRow.cpp:482
bool endReached() const
determine whether iterator is at 1 beyond the last row in range
Definition XLRow.hpp:386
XLRowIterator(const XLRowRange &rowRange, XLIteratorLocation loc)
Definition XLRow.cpp:325
bool operator==(const XLRowIterator &rhs) const
Definition XLRow.cpp:466
int64_t difference_type
Definition XLRow.hpp:279
Definition XLRow.hpp:416
XLRowRange & operator=(XLRowRange &&other) noexcept
XLRowRange & operator=(const XLRowRange &other)
Definition XLRow.cpp:515
XLRowIterator end()
Definition XLRow.cpp:531
uint32_t rowCount() const
Definition XLRow.cpp:527
XLRowIterator begin()
Definition XLRow.cpp:529
friend class XLRowIterator
Definition XLRow.hpp:417
XLRowRange(XLRowRange &&other) noexcept
XLRowRange(const XMLNode &dataNode, uint32_t first, uint32_t last, const XLSharedStrings &sharedStrings)
Definition XLRow.cpp:497
The XLRow class represent a row in an Excel spreadsheet. Using XLRow objects, various row formatting ...
Definition XLRow.hpp:34
void setHeight(float height)
Set the height of the row.
Definition XLRow.cpp:99
uint8_t outlineLevel() const
Get the outline level of the row.
Definition XLRow.cpp:145
XLRow & operator=(const XLRow &other)
Copy assignment operator.
Definition XLRow.cpp:59
float descent() const
Get the descent of the row, which is the vertical distance in pixels from the bottom of the cells in ...
Definition XLRow.cpp:109
void setCollapsed(bool state)
Set the row to be collapsed or expanded.
Definition XLRow.cpp:186
friend bool operator>=(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:543
double height() const
Get the height of the row.
Definition XLRow.cpp:90
~XLRow()
Destructor.
XLRowDataProxy & values()
Definition XLRow.cpp:215
friend bool operator<(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:519
T values() const
Definition XLRow.hpp:202
friend class XLRowIterator
Definition XLRow.hpp:35
uint16_t cellCount() const
Get the number of cells in the row.
Definition XLRow.cpp:207
friend bool operator<=(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:535
bool isCollapsed() const
Is the row collapsed?
Definition XLRow.cpp:180
bool empty() const
test if row object has no (valid) content
Definition XLRow.cpp:83
void setDescent(float descent)
Set the descent of the row, which is he vertical distance in pixels from the bottom of the cells in t...
Definition XLRow.cpp:118
XLRowProperties properties() const
Get row properties as a value-semantic POD struct.
Definition XLRow.cpp:164
friend bool operator!=(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:511
XLRow()
Default constructor.
Definition XLRow.cpp:26
void setHidden(bool state)
Set the row to be hidden or visible.
Definition XLRow.cpp:133
void setProperties(const XLRowProperties &props)
Set row properties from a value-semantic POD struct in a single pass.
Definition XLRow.cpp:170
friend bool operator>(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:527
void setOutlineLevel(uint8_t level)
Set the outline level of the row.
Definition XLRow.cpp:154
friend bool operator==(const XLRow &lhs, const XLRow &rhs)
Definition XLRow.hpp:503
uint32_t rowNumber() const
Definition XLRow.cpp:202
friend class XLRowDataProxy
Definition XLRow.hpp:36
bool isHidden() const
Is the row hidden?
Definition XLRow.cpp:127
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual str...
Definition XLSharedStrings.hpp:78
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:132
Definition IXLCellProvider.hpp:24
XLIteratorLocation
Definition XLIterator.hpp:17
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:314
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:321
bool operator<=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially precedes or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:254
bool operator<(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Evaluates precedence primarily by row, then by column, allowing cell ranges to be sorted efficiently ...
Definition XLCellReference.hpp:243
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36
bool operator>=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially follows or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:259
bool operator>(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Inverts the less-than operator logic to verify strict left-to-right, top-to-bottom traversal dominanc...
Definition XLCellReference.hpp:249
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:67
Plain POD properties describing an OOXML Row (<row> element).
Definition XLXmlSchema.hpp:168