OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLSheet.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_XLSHEET_HPP
12#define OPENXLSX_XLSHEET_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// ===== External Includes ===== //
21#include <ostream>
22#include <variant>
23
24// ===== OpenXLSX Includes ===== //
25#include "OpenXLSX-Exports.hpp"
26#include "XLChartsheet.hpp"
28#include "XLSheetBase.hpp"
29#include "XLWorksheet.hpp"
30#include "XLXmlFile.hpp"
31
32namespace OpenXLSX
33{
39 class OPENXLSX_EXPORT XLSheet final : public XLXmlFile
40 {
41 public:
48 explicit XLSheet(XLXmlData* xmlData);
49
55 XLSheet(const XLSheet& other) = default;
56
61 XLSheet(XLSheet&& other) noexcept = default;
62
67 ~XLSheet() = default;
68
74 XLSheet& operator=(const XLSheet& other) = default;
75
81 XLSheet& operator=(XLSheet&& other) noexcept = default;
82
88
95 void setVisibility(XLSheetState state);
96
101 XLColor color() const;
102
107 void setColor(const XLColor& color);
108
113 uint16_t index() const;
114
118 void setIndex(uint16_t index);
119
124 std::string name() const;
125
130 void setName(const std::string& name);
131
136 bool isSelected() const;
137
142 void setSelected(bool selected);
143
148 bool isActive() const;
149
153 bool setActive();
154
159 template<typename SheetType,
160 typename = std::enable_if_t<std::is_same_v<SheetType, XLWorksheet> or std::is_same_v<SheetType, XLChartsheet>>>
161 bool isType() const
162 { return std::holds_alternative<SheetType>(m_sheet); }
163
170 void clone(const std::string& newName);
171
177 template<typename T, typename = std::enable_if_t<std::is_same_v<T, XLWorksheet> or std::is_same_v<T, XLChartsheet>>>
178 T get() const
179 {
180 try {
181 if constexpr (std::is_same<T, XLWorksheet>::value)
182 return std::get<XLWorksheet>(m_sheet);
183
184 else if constexpr (std::is_same<T, XLChartsheet>::value)
185 return std::get<XLChartsheet>(m_sheet);
186 }
187
188 catch (const std::bad_variant_access&) {
189 throw XLSheetError("XLSheet object does not contain the requested sheet type.");
190 }
191 }
192
197 operator XLWorksheet() const; // NOLINT
198
203 operator XLChartsheet() const; // NOLINT
204
208 void print(std::basic_ostream<char>& ostr) const;
209
210 private: // ---------- Private Member Variables ---------- //
211 std::variant<XLWorksheet, XLChartsheet> m_sheet;
212 };
213} // namespace OpenXLSX
214
215#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
216# pragma warning(pop)
217#endif // _MSC_VER
218
219#endif // OPENXLSX_XLSHEET_HPP
Class representing an Excel chartsheet.
Definition XLChartsheet.hpp:25
Definition XLColor.hpp:32
Definition XLException.hpp:96
uint16_t index() const
Method for getting the index of the sheet.
Definition XLSheet.cpp:164
XLSheet(const XLSheet &other)=default
The copy constructor.
bool isType() const
Method to get the type of the sheet.
Definition XLSheet.hpp:161
T get() const
Definition XLSheet.hpp:178
void setIndex(uint16_t index)
Method for setting the index of the sheet. This effectively moves the sheet to a different position.
Definition XLSheet.cpp:169
XLSheet & operator=(const XLSheet &other)=default
Assignment operator.
bool isSelected() const
Determine whether the sheet is selected.
Definition XLSheet.cpp:184
void setVisibility(XLSheetState state)
Method for setting the state of the sheet.
Definition XLSheet.cpp:149
XLSheet & operator=(XLSheet &&other) noexcept=default
XLSheet(XLXmlData *xmlData)
The constructor. There are no default constructor, so all parameters must be provided for constructin...
Definition XLSheet.cpp:136
XLSheetState visibility() const
Method for getting the current visibility state of the sheet.
Definition XLSheet.cpp:144
void setName(const std::string &name)
Method for renaming the sheet.
Definition XLSheet.cpp:179
bool setActive()
Definition XLSheet.cpp:199
void setColor(const XLColor &color)
Definition XLSheet.cpp:159
XLSheet(XLSheet &&other) noexcept=default
~XLSheet()=default
The destructor.
bool isActive() const
Definition XLSheet.cpp:194
void setSelected(bool selected)
Definition XLSheet.cpp:189
std::string name() const
Method to retrieve the name of the sheet.
Definition XLSheet.cpp:174
XLColor color() const
Definition XLSheet.cpp:154
A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook ob...
Definition XLWorksheet.hpp:132
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:79
std::string xmlData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Method for getting the XML data represented by the object.
Definition XLXmlFile.cpp:49
XLXmlFile()=default
Default constructor.
Definition IXLCellProvider.hpp:24
XLSheetState
The XLSheetState is an enumeration of the possible (visibility) states, e.g. Visible or Hidden.
Definition XLSheetBase.hpp:35