OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLWorkbook.hpp
Go to the documentation of this file.
1#ifndef OPENXLSX_XLWORKBOOK_HPP
2#define OPENXLSX_XLWORKBOOK_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 <optional>
12#include <ostream> // std::basic_ostream
13#include <string>
14#include <string_view>
15#include <vector>
16
17// ===== OpenXLSX Includes ===== //
18#include "OpenXLSX-Exports.hpp"
19#include "XLXmlFile.hpp"
20
21namespace OpenXLSX
22{
23 class XLSheet;
24 class XLWorksheet;
25 class XLChartsheet;
26
31
35 class OPENXLSX_EXPORT XLDefinedName
36 {
37 public:
38 XLDefinedName() = default;
39 explicit XLDefinedName(const XMLNode& node);
40
41 std::string name() const;
42 void setName(std::string_view name);
43
44 std::string refersTo() const;
45 void setRefersTo(std::string_view formula);
46
47 std::optional<uint32_t> localSheetId() const;
48 void setLocalSheetId(uint32_t id);
49
50 bool hidden() const;
51 void setHidden(bool hidden);
52
53 std::string comment() const;
54 void setComment(std::string_view comment);
55
56 bool valid() const { return !m_node.empty(); }
57
58 private:
59 XMLNode m_node;
60 };
61
65 class OPENXLSX_EXPORT XLDefinedNames
66 {
67 public:
68 XLDefinedNames() = default;
69 explicit XLDefinedNames(const XMLNode& node);
70
71 XLDefinedName append(std::string_view name, std::string_view formula, std::optional<uint32_t> localSheetId = std::nullopt);
72 void remove(std::string_view name, std::optional<uint32_t> localSheetId = std::nullopt);
73 XLDefinedName get(std::string_view name, std::optional<uint32_t> localSheetId = std::nullopt) const;
74 std::vector<XLDefinedName> all() const;
75 bool exists(std::string_view name, std::optional<uint32_t> localSheetId = std::nullopt) const;
76 size_t count() const;
77
78 private:
79 XMLNode m_node;
80 };
81
86 class OPENXLSX_EXPORT XLWorkbook : public XLXmlFile
87 {
88 friend class XLSheet;
89 friend class XLDocument;
90
91 public: // ---------- Public Member Functions ---------- //
95 XLWorkbook() = default;
96
102 explicit XLWorkbook(XLXmlData* xmlData);
103
108 XLWorkbook(const XLWorkbook& other) = default;
109
114 XLWorkbook(XLWorkbook&& other) = default;
115
120
124 XLWorkbook& operator=(const XLWorkbook& other) = default;
125
129 XLWorkbook& operator=(XLWorkbook&& other) = default;
130
137 XLSheet sheet(uint16_t index);
138
144 XLSheet sheet(std::string_view sheetName);
145
151 XLWorksheet worksheet(std::string_view sheetName);
152
158 XLWorksheet worksheet(uint16_t index);
159
165 XLChartsheet chartsheet(std::string_view sheetName);
166
172 XLChartsheet chartsheet(uint16_t index);
173
178 XLDefinedNames definedNames();
179
185 void deleteSheet(std::string_view sheetName);
186
191 void addWorksheet(std::string_view sheetName);
192 void addChartsheet(std::string_view sheetName);
193
199 void cloneSheet(std::string_view existingName, std::string_view newName);
200
206 void setSheetIndex(std::string_view sheetName, unsigned int index);
207
213 unsigned int indexOfSheet(std::string_view sheetName) const;
214
220 XLSheetType typeOfSheet(std::string_view sheetName) const;
221
227 XLSheetType typeOfSheet(unsigned int index) const;
228
232 unsigned int sheetCount() const;
233
237 unsigned int worksheetCount() const;
238
242 unsigned int chartsheetCount() const;
243
247 std::vector<std::string> sheetNames() const;
248
252 std::vector<std::string> worksheetNames() const;
253
257 std::vector<std::string> chartsheetNames() const;
258
262 bool sheetExists(std::string_view sheetName) const;
263
267 bool worksheetExists(std::string_view sheetName) const;
268
272 bool chartsheetExists(std::string_view sheetName) const;
273
277 void updateSheetReferences(std::string_view oldName, std::string_view newName);
278
282 void deleteNamedRanges();
283
287 void updateWorksheetDimensions();
288
292 void setFullCalculationOnLoad();
293
300 void protect(bool lockStructure, bool lockWindows, std::string_view password = "");
301
305 void unprotect();
306
310 bool isProtected() const;
311
315 void print(std::basic_ostream<char>& ostr) const;
316
317 private: // ---------- Private Member Functions ---------- //
321 uint16_t createInternalSheetID();
322
326 std::string sheetID(std::string_view sheetName);
327
331 std::string sheetName(std::string_view sheetID) const;
332
336 std::string sheetVisibility(std::string_view sheetID) const;
337
341 void prepareSheetMetadata(std::string_view sheetName, uint16_t internalID, std::string_view sheetPath = "");
342
346 void setSheetName(std::string_view sheetRID, std::string_view newName);
347
351 void setSheetVisibility(std::string_view sheetRID, std::string_view state);
352
356 bool sheetIsActive(std::string_view sheetRID) const;
357
361 bool setSheetActive(std::string_view sheetRID);
362
366 bool isVisibleState(std::string_view state) const;
367
371 bool isVisible(XMLNode const& sheetNode) const;
372 };
373} // namespace OpenXLSX
374
375#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
376# pragma warning(pop)
377#endif // _MSC_VER
378
379#endif // OPENXLSX_XLWORKBOOK_HPP
XLXmlData * xmlData
Definition XLDocument.cpp:1422
Definition XLXmlParser.hpp:84
Class representing an Excel chartsheet.
Definition XLChartsheet.hpp:15
A class representing a single defined name in a workbook.
Definition XLWorkbook.hpp:36
bool valid() const
Definition XLWorkbook.hpp:56
A class representing the collection of defined names in a workbook.
Definition XLWorkbook.hpp:66
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:82
The XLAbstractSheet is a generalized sheet class, which functions as superclass for specialized class...
Definition XLSheet.hpp:30
This class encapsulates the concept of a Workbook. It provides access to the individual sheets (works...
Definition XLWorkbook.hpp:87
XLWorkbook & operator=(XLWorkbook &&other)=default
Move assignment operator.
XLWorkbook & operator=(const XLWorkbook &other)=default
Copy assignment operator.
~XLWorkbook()
Destructor.
XLWorkbook()=default
Default constructor. Creates an empty ('null') XLWorkbook object.
XLWorkbook(const XLWorkbook &other)=default
Copy Constructor.
XLWorkbook(XLWorkbook &&other)=default
Move constructor.
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
XLSheetType
Enumeration of the different types of sheets.
Definition XLWorkbook.hpp:30