1#ifndef OPENXLSX_XLSHEETBASE_HPP
2#define OPENXLSX_XLSHEETBASE_HPP
4#include "OpenXLSX-Exports.hpp"
11#include <shared_mutex>
52 template<
typename T,
typename = std::enable_if_t<std::is_same_v<T, XLWorksheet> or std::is_same_v<T, XLChartsheet>>>
108 XLQuery query(XLQueryType::QuerySheetVisibility);
109 query.
setParam(
"sheetID", relationshipID());
110 const auto state = parentDoc().execQuery(query).template result<std::string>();
111 auto result = XLSheetState::Visible;
113 if (state ==
"visible" or state.empty()) { result = XLSheetState::Visible; }
114 else if (state ==
"hidden") {
115 result = XLSheetState::Hidden;
117 else if (state ==
"veryHidden") {
118 result = XLSheetState::VeryHidden;
130 std::unique_lock<std::shared_mutex> lock(parentDoc().mutex());
131 auto stateString = std::string();
133 case XLSheetState::Visible:
134 stateString =
"visible";
137 case XLSheetState::Hidden:
138 stateString =
"hidden";
141 case XLSheetState::VeryHidden:
142 stateString =
"veryHidden";
146 parentDoc().execCommand(
XLCommand(XLCommandType::SetSheetVisibility)
147 .setParam(
"sheetID", relationshipID())
148 .setParam(
"sheetVisibility", stateString));
156 XLColor color()
const {
return static_cast<const T&
>(*this).getColor_impl(); }
171 XLQuery query(XLQueryType::QuerySheetIndex);
172 query.
setParam(
"sheetID", relationshipID());
173 return static_cast<uint16_t
>(std::stoi(parentDoc().execQuery(query).
template result<std::string>()));
182 std::unique_lock<std::shared_mutex> lock(parentDoc().mutex());
183 parentDoc().execCommand(
184 XLCommand(XLCommandType::SetSheetIndex).setParam(
"sheetID", relationshipID()).setParam(
"sheetIndex", index));
193 XLQuery query(XLQueryType::QuerySheetName);
194 query.
setParam(
"sheetID", relationshipID());
195 return parentDoc().execQuery(query).template result<std::string>();
204 std::unique_lock<std::shared_mutex> lock(parentDoc().mutex());
205 parentDoc().execCommand(
XLCommand(XLCommandType::SetSheetName)
206 .setParam(
"sheetID", relationshipID())
207 .setParam(
"sheetName", name())
208 .setParam(
"newName", sheetName));
215 bool isSelected()
const {
return static_cast<const T&
>(*this).isSelected_impl(); }
221 void setSelected(
bool selected) {
static_cast<T&
>(*this).setSelected_impl(selected); }
227 bool isActive()
const {
return static_cast<const T&
>(*this).isActive_impl(); }
232 bool setActive() {
return static_cast<T&
>(*this).setActive_impl(); }
240 void clone(
const std::string& newName)
242 parentDoc().execCommand(
243 XLCommand(XLCommandType::CloneSheet).setParam(
"sheetID", relationshipID()).setParam(
"cloneName", newName));
XLXmlData * xmlData
Definition XLDocument.cpp:1422
Definition XLColor.hpp:22
Definition XLCommandQuery.hpp:43
Definition XLCommandQuery.hpp:106
XLQuery & setParam(const std::string ¶m, T value)
Definition XLCommandQuery.hpp:122
The XLSheetBase class is the base class for the XLWorksheet and XLChartsheet classes....
Definition XLSheetBase.hpp:54
bool setActive()
Definition XLSheetBase.hpp:232
bool isSelected() const
Definition XLSheetBase.hpp:215
std::string name() const
Method to retrieve the name of the sheet.
Definition XLSheetBase.hpp:191
bool isActive() const
Definition XLSheetBase.hpp:227
uint16_t index() const
look up sheet name via relationshipID, then attempt to match that to a sheet in XLWorkbook::sheet(uin...
Definition XLSheetBase.hpp:169
XLSheetBase(const XLSheetBase &other)=default
The copy constructor.
XLColor color() const
Definition XLSheetBase.hpp:156
void setIndex(uint16_t index)
Definition XLSheetBase.hpp:180
void clone(const std::string &newName)
Method for cloning the sheet.
Definition XLSheetBase.hpp:240
void setColor(const XLColor &color)
Definition XLSheetBase.hpp:162
~XLSheetBase()=default
The destructor.
void setVisibility(XLSheetState state)
Definition XLSheetBase.hpp:128
void setName(const std::string &sheetName)
Method for renaming the sheet.
Definition XLSheetBase.hpp:202
XLSheetState visibility() const
Definition XLSheetBase.hpp:106
XLSheetBase & operator=(const XLSheetBase &)=default
Assignment operator.
XLSheetBase & operator=(XLSheetBase &&other) noexcept=default
XLSheetBase()
Constructor.
Definition XLSheetBase.hpp:59
XLSheetBase(XLXmlData *xmlData)
The constructor. There are no default constructor, so all parameters must be provided for constructin...
Definition XLSheetBase.hpp:67
void setSelected(bool selected)
Definition XLSheetBase.hpp:221
XLSheetBase(XLSheetBase &&other) noexcept=default
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
OPENXLSX_EXPORT void setTabSelected(const XMLDocument &xmlDocument, bool selected)
Set the tab selected property to desired value.
Definition XLSheet.cpp:37
XLPaneState
The XLPaneState is an enumeration of the possible states of a pane, e.g. Frozen or Split.
Definition XLSheetBase.hpp:30
constexpr const bool XLEmptyHiddenCells
Definition XLSheetBase.hpp:20
OPENXLSX_EXPORT XLPaneState XLPaneStateFromString(std::string const &stateString)
inverse of XLPaneStateToString
Definition XLSheet.cpp:83
OpenXLSX_xml_document XMLDocument
Definition XLXmlParser.hpp:65
OPENXLSX_EXPORT XLPane XLPaneFromString(std::string const &paneString)
inverse of XLPaneToString
Definition XLSheet.cpp:116
XLPane
The XLPane is an enumeration of the possible pane identifiers.
Definition XLSheetBase.hpp:35
XLSheetState
The XLSheetState is an enumeration of the possible (visibility) states, e.g. Visible or Hidden.
Definition XLSheetBase.hpp:25
OPENXLSX_EXPORT bool tabIsSelected(const XMLDocument &xmlDocument)
Function for checking if the tab is selected.
Definition XLSheet.cpp:51
OPENXLSX_EXPORT std::string XLPaneStateToString(XLPaneState state)
get the correct XLPaneState from the OOXML pane state attribute string
Definition XLSheet.cpp:65
OPENXLSX_EXPORT void setTabColor(const XMLDocument &xmlDocument, const XLColor &color)
Function for setting tab color.
Definition XLSheet.cpp:19
OPENXLSX_EXPORT std::string XLPaneToString(XLPane pane)
get the correct XLPane from the OOXML pane identifier attribute string
Definition XLSheet.cpp:96