OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLSheet.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLSHEET_HPP
2#define OPENXLSX_XLSHEET_HPP
3
4#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
5# pragma warning(push)
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
8#endif // _MSC_VER
9
10// ===== External Includes ===== //
11#include <ostream>
12#include <variant>
13
14// ===== OpenXLSX Includes ===== //
15#include "OpenXLSX-Exports.hpp"
16#include "XLChartsheet.hpp"
18#include "XLSheetBase.hpp"
19#include "XLWorksheet.hpp"
20#include "XLXmlFile.hpp"
21
22namespace OpenXLSX
23{
29 class OPENXLSX_EXPORT XLSheet final : public XLXmlFile
30 {
31 public:
38 explicit XLSheet(XLXmlData* xmlData);
39
45 XLSheet(const XLSheet& other) = default;
46
51 XLSheet(XLSheet&& other) noexcept = default;
52
57 ~XLSheet() = default;
58
64 XLSheet& operator=(const XLSheet& other) = default;
65
71 XLSheet& operator=(XLSheet&& other) noexcept = default;
72
77 XLSheetState visibility() const;
78
85 void setVisibility(XLSheetState state);
86
91 XLColor color() const;
92
97 void setColor(const XLColor& color);
98
103 uint16_t index() const;
104
108 void setIndex(uint16_t index);
109
114 std::string name() const;
115
120 void setName(const std::string& name);
121
126 bool isSelected() const;
127
132 void setSelected(bool selected);
133
138 bool isActive() const;
139
143 bool setActive();
144
149 template<typename SheetType,
150 typename = std::enable_if_t<std::is_same_v<SheetType, XLWorksheet> or std::is_same_v<SheetType, XLChartsheet>>>
151 bool isType() const
152 { return std::holds_alternative<SheetType>(m_sheet); }
153
160 void clone(const std::string& newName);
161
167 template<typename T, typename = std::enable_if_t<std::is_same_v<T, XLWorksheet> or std::is_same_v<T, XLChartsheet>>>
168 T get() const
169 {
170 try {
171 if constexpr (std::is_same<T, XLWorksheet>::value)
172 return std::get<XLWorksheet>(m_sheet);
173
174 else if constexpr (std::is_same<T, XLChartsheet>::value)
175 return std::get<XLChartsheet>(m_sheet);
176 }
177
178 catch (const std::bad_variant_access&) {
179 throw XLSheetError("XLSheet object does not contain the requested sheet type.");
180 }
181 }
182
187 operator XLWorksheet() const; // NOLINT
188
193 operator XLChartsheet() const; // NOLINT
194
198 void print(std::basic_ostream<char>& ostr) const;
199
200 private: // ---------- Private Member Variables ---------- //
201 std::variant<XLWorksheet, XLChartsheet> m_sheet;
202 };
203} // namespace OpenXLSX
204
205#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
206# pragma warning(pop)
207#endif // _MSC_VER
208
209#endif // OPENXLSX_XLSHEET_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
Class representing an Excel chartsheet.
Definition XLChartsheet.hpp:15
Definition XLColor.hpp:22
Definition XLException.hpp:86
The XLAbstractSheet is a generalized sheet class, which functions as superclass for specialized class...
Definition XLSheet.hpp:30
XLSheet(const XLSheet &other)=default
The copy constructor.
bool isType() const
Method to get the type of the sheet.
Definition XLSheet.hpp:151
T get() const
Definition XLSheet.hpp:168
XLSheet & operator=(const XLSheet &other)=default
Assignment operator.
XLSheet & operator=(XLSheet &&other) noexcept=default
XLSheet(XLSheet &&other) noexcept=default
~XLSheet()=default
The destructor.
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
XLSheetState
The XLSheetState is an enumeration of the possible (visibility) states, e.g. Visible or Hidden.
Definition XLSheetBase.hpp:25