OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLMergeCells.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLMERGECELLS_HPP
2#define OPENXLSX_XLMERGECELLS_HPP
3
4#ifdef _MSC_VER
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif
9
10#include <deque>
11#include <limits>
12#include <memory>
13#include <ostream>
14#include <string>
15#include <string_view>
16#include <vector>
17
18// ===== OpenXLSX Includes ===== //
19#include "OpenXLSX-Exports.hpp"
20#include "XLCellReference.hpp"
21#include "XLXmlParser.hpp"
22
23namespace OpenXLSX
24{
25 typedef int32_t XLMergeIndex;
26 constexpr const XLMergeIndex XLMergeNotFound = -1;
27
28 constexpr size_t XLMaxMergeCells = (std::numeric_limits<XLMergeIndex>::max)();
29
37 class OPENXLSX_EXPORT XLMergeCells
38 {
39 public:
43 struct XLRect
44 {
45 uint32_t top;
46 uint16_t left;
47 uint32_t bottom;
48 uint16_t right;
49
53 [[nodiscard]] bool contains(uint32_t row, uint16_t col) const noexcept
54 { return row >= top && row <= bottom && col >= left && col <= right; }
55
60 [[nodiscard]] bool overlaps(const XLRect& other) const noexcept
61 { return top <= other.bottom && bottom >= other.top && left <= other.right && right >= other.left; }
62 };
63
65 {
66 std::string reference;
68 };
69
70 public:
72
77 explicit XLMergeCells(const XMLNode& rootNode, std::vector<std::string_view> const& nodeOrder);
78
79 ~XLMergeCells() = default;
80 XLMergeCells(const XLMergeCells& other) = default;
81 XLMergeCells(XLMergeCells&& other) noexcept = default;
82 XLMergeCells& operator=(const XLMergeCells& other) = default;
83 XLMergeCells& operator=(XLMergeCells&& other) noexcept = default;
84
88 [[nodiscard]] bool valid() const;
89
93 [[nodiscard]] XLMergeIndex findMerge(std::string_view reference) const;
94
95 [[nodiscard]] bool mergeExists(std::string_view reference) const;
96
100 [[nodiscard]] XLMergeIndex findMergeByCell(std::string_view cellRef) const;
101 [[nodiscard]] XLMergeIndex findMergeByCell(XLCellReference cellRef) const;
102
103 [[nodiscard]] size_t count() const;
104
108 [[nodiscard]] const char* merge(XLMergeIndex index) const;
109
110 [[nodiscard]] const char* operator[](XLMergeIndex index) const { return merge(index); }
111
116 XLMergeIndex appendMerge(const std::string& reference);
117
121 void deleteMerge(XLMergeIndex index);
122
126 void deleteAll();
127
136 void shiftRows(int32_t delta, uint32_t fromRow);
137
143 void shiftCols(int32_t delta, uint16_t fromCol);
144
145 void print(std::basic_ostream<char>& ostr) const;
146
147 private:
148 XMLNode m_rootNode;
149 std::vector<std::string_view> m_nodeOrder;
150 XMLNode m_mergeCellsNode;
151 std::deque<XLMergeEntry> m_mergeCache;
152 };
153} // namespace OpenXLSX
154
155#ifdef _MSC_VER
156# pragma warning(pop)
157#endif
158
159#endif // OPENXLSX_XLMERGECELLS_HPP
Definition XLXmlParser.hpp:84
Definition XLCellReference.hpp:34
Manages merged cell ranges in a worksheet.
Definition XLMergeCells.hpp:38
XLMergeCells(const XLMergeCells &other)=default
const char * operator[](XLMergeIndex index) const
Definition XLMergeCells.hpp:110
XLMergeCells(XLMergeCells &&other) noexcept=default
XLMergeCells & operator=(XLMergeCells &&other) noexcept=default
XLMergeCells & operator=(const XLMergeCells &other)=default
Definition IZipArchive.hpp:18
constexpr const XLMergeIndex XLMergeNotFound
Definition XLMergeCells.hpp:26
constexpr size_t XLMaxMergeCells
Definition XLMergeCells.hpp:28
int32_t XLMergeIndex
Definition XLMergeCells.hpp:25
Definition XLMergeCells.hpp:65
std::string reference
Definition XLMergeCells.hpp:66
XLRect rect
Definition XLMergeCells.hpp:67
Internal numerical bounds representation for constant-time coordinate tests.
Definition XLMergeCells.hpp:44
uint32_t top
Definition XLMergeCells.hpp:45
uint16_t left
Definition XLMergeCells.hpp:46
uint16_t right
Definition XLMergeCells.hpp:48
uint32_t bottom
Definition XLMergeCells.hpp:47
bool overlaps(const XLRect &other) const noexcept
Detect spatial intersection between two regions to prevent overlapping merges, which are illegal in t...
Definition XLMergeCells.hpp:60
bool contains(uint32_t row, uint16_t col) const noexcept
Determine if a cell coordinate is within the merged region.
Definition XLMergeCells.hpp:53