react-native-nitro-xlsx 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +20 -8
  2. package/cpp/HybridNitroXlsx.cpp +25 -1
  3. package/cpp/HybridXlsxCellFormat.cpp +46 -146
  4. package/cpp/HybridXlsxCellFormat.hpp +9 -41
  5. package/cpp/HybridXlsxConditionalFormat.cpp +4 -1
  6. package/cpp/HybridXlsxConditionalFormats.cpp +5 -1
  7. package/cpp/HybridXlsxWorkbook.cpp +38 -8
  8. package/cpp/HybridXlsxWorkbook.hpp +10 -1
  9. package/cpp/HybridXlsxWorksheet.cpp +422 -141
  10. package/cpp/HybridXlsxWorksheet.hpp +4 -1
  11. package/cpp/XlsxCacheDir.cpp +25 -2
  12. package/cpp/XlsxCacheDir.hpp +3 -1
  13. package/cpp/XlsxCellStyle.hpp +360 -0
  14. package/cpp/XlsxJson.cpp +29 -8
  15. package/package.json +1 -1
  16. package/scripts/sync-openxlsx-headers.sh +34 -0
  17. package/src/__mocks__/react-native-nitro-modules.ts +523 -20
  18. package/src/__tests__/index.test.ts +124 -16
  19. package/src/index.ts +13 -13
  20. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/IZipArchive.hpp +361 -0
  21. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/OpenXLSX-Exports.hpp +12 -0
  22. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCell.hpp +367 -0
  23. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellIterator.hpp +252 -0
  24. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellRange.hpp +223 -0
  25. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellReference.hpp +317 -0
  26. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellValue.hpp +793 -0
  27. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColor.hpp +232 -0
  28. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColumn.hpp +159 -0
  29. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCommandQuery.hpp +228 -0
  30. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLComments.hpp +270 -0
  31. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLConstants.hpp +18 -0
  32. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLContentTypes.hpp +264 -0
  33. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDateTime.hpp +175 -0
  34. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDocument.hpp +505 -0
  35. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDrawing.hpp +452 -0
  36. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLException.hpp +161 -0
  37. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLFormula.hpp +375 -0
  38. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLIterator.hpp +40 -0
  39. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLMergeCells.hpp +216 -0
  40. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLProperties.hpp +348 -0
  41. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRelationships.hpp +348 -0
  42. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRow.hpp +721 -0
  43. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRowData.hpp +488 -0
  44. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSharedStrings.hpp +204 -0
  45. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSheet.hpp +1640 -0
  46. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLStyles.hpp +2390 -0
  47. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLTables.hpp +132 -0
  48. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLWorkbook.hpp +404 -0
  49. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlData.hpp +283 -0
  50. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlFile.hpp +194 -0
  51. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParser.hpp +282 -0
  52. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParserForwardDeclarations.hpp +85 -0
  53. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLZipArchive.hpp +232 -0
  54. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/LibZip.hpp +447 -0
  55. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/OpenXLSXFileSystemTools.hpp +207 -0
  56. package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/Zippy.hpp +1375 -0
  57. package/thirdparty/README.md +7 -3
@@ -0,0 +1,1640 @@
1
+ /*
2
+
3
+ ____ ____ ___ ____ ____ ____ ___
4
+ 6MMMMb `MM( )M' `MM' 6MMMMb\`MM( )M'
5
+ 8P Y8 `MM. d' MM 6M' ` `MM. d'
6
+ 6M Mb __ ____ ____ ___ __ `MM. d' MM MM `MM. d'
7
+ MM MM `M6MMMMb 6MMMMb `MM 6MMb `MM. d' MM YM. `MM. d'
8
+ MM MM MM' `Mb 6M' `Mb MMM9 `Mb `MMd MM YMMMMb `MMd
9
+ MM MM MM MM MM MM MM' MM dMM. MM `Mb dMM.
10
+ MM MM MM MM MMMMMMMM MM MM d'`MM. MM MM d'`MM.
11
+ YM M9 MM MM MM MM MM d' `MM. MM MM d' `MM.
12
+ 8b d8 MM. ,M9 YM d9 MM MM d' `MM. MM / L ,M9 d' `MM.
13
+ YMMMM9 MMYMMM9 YMMMM9 _MM_ _MM_M(_ _)MM_ _MMMMMMM MYMMMM9 _M(_ _)MM_
14
+ MM
15
+ MM
16
+ _MM_
17
+
18
+ Copyright (c) 2018, Kenneth Troldal Balslev
19
+
20
+ All rights reserved.
21
+
22
+ Redistribution and use in source and binary forms, with or without
23
+ modification, are permitted provided that the following conditions are met:
24
+ - Redistributions of source code must retain the above copyright
25
+ notice, this list of conditions and the following disclaimer.
26
+ - Redistributions in binary form must reproduce the above copyright
27
+ notice, this list of conditions and the following disclaimer in the
28
+ documentation and/or other materials provided with the distribution.
29
+ - Neither the name of the author nor the
30
+ names of any contributors may be used to endorse or promote products
31
+ derived from this software without specific prior written permission.
32
+
33
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
37
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+
44
+ */
45
+
46
+ #ifndef OPENXLSX_XLSHEET_HPP
47
+ #define OPENXLSX_XLSHEET_HPP
48
+
49
+ #ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
50
+ # pragma warning(push)
51
+ # pragma warning(disable : 4251)
52
+ # pragma warning(disable : 4275)
53
+ #endif // _MSC_VER
54
+
55
+ // ===== External Includes ===== //
56
+ #include <cstdint> // uint8_t, uint16_t, uint32_t
57
+ #include <ostream> // std::basic_ostream
58
+ #include <string_view> // std::string_view
59
+ #include <type_traits>
60
+ #include <variant>
61
+ #include <vector> // std::vector< std::string_view >
62
+
63
+ // ===== OpenXLSX Includes ===== //
64
+ #include "OpenXLSX-Exports.hpp"
65
+ #include "XLCell.hpp"
66
+ #include "XLCellRange.hpp"
67
+ #include "XLCellReference.hpp"
68
+ #include "XLColor.hpp"
69
+ #include "XLColumn.hpp"
70
+ #include "XLCommandQuery.hpp"
71
+ #include "XLComments.hpp" // XLComments
72
+ #include "XLDocument.hpp"
73
+ #include "XLException.hpp"
74
+ #include "XLMergeCells.hpp"
75
+ #include "XLRow.hpp"
76
+ #include "XLStyles.hpp" // XLStyleIndex
77
+ #include "XLTables.hpp" // XLTables
78
+ #include "XLXmlFile.hpp"
79
+
80
+ namespace OpenXLSX
81
+ {
82
+ constexpr const bool XLEmptyHiddenCells = true; // readability constant for XLWorksheet::mergeCells parameter emptyHiddenCells
83
+
84
+ constexpr const bool XLCalculateLastCell = true; // readability constant for XLWorksheet::setDimension parameter autoCalculateLastCell
85
+ constexpr const bool XLDoNotCalculateLastCell = false; // "
86
+
87
+ /**
88
+ * @brief The XLSheetState is an enumeration of the possible (visibility) states, e.g. Visible or Hidden.
89
+ */
90
+ enum class XLSheetState : uint8_t { Visible, Hidden, VeryHidden };
91
+
92
+ constexpr const uint16_t XLPriorityNotSet = 0; // readability constant for XLCfRule::priority()
93
+
94
+ enum class XLCfType : uint8_t {
95
+ Expression = 0,
96
+ CellIs = 1,
97
+ ColorScale = 2,
98
+ DataBar = 3,
99
+ IconSet = 4,
100
+ Top10 = 5,
101
+ UniqueValues = 6,
102
+ DuplicateValues = 7,
103
+ ContainsText = 8,
104
+ NotContainsText = 9,
105
+ BeginsWith = 10,
106
+ EndsWith = 11,
107
+ ContainsBlanks = 12,
108
+ NotContainsBlanks = 13,
109
+ ContainsErrors = 14,
110
+ NotContainsErrors = 15,
111
+ TimePeriod = 16,
112
+ AboveAverage = 17,
113
+ Invalid = 255
114
+ };
115
+
116
+ enum class XLCfOperator : uint8_t {
117
+ LessThan = 0,
118
+ LessThanOrEqual = 1,
119
+ Equal = 2,
120
+ NotEqual = 3,
121
+ GreaterThanOrEqual = 4,
122
+ GreaterThan = 5,
123
+ Between = 6,
124
+ NotBetween = 7,
125
+ ContainsText = 8,
126
+ NotContains = 9,
127
+ BeginsWith = 10,
128
+ EndsWith = 11,
129
+ Invalid = 255
130
+ };
131
+
132
+ enum class XLCfTimePeriod : uint8_t {
133
+ Today = 0,
134
+ Yesterday = 1,
135
+ Tomorrow = 2,
136
+ Last7Days = 3,
137
+ ThisMonth = 4,
138
+ LastMonth = 5,
139
+ NextMonth = 6,
140
+ ThisWeek = 7,
141
+ LastWeek = 8,
142
+ NextWeek = 9,
143
+ Invalid = 255
144
+ };
145
+
146
+ const std::vector< std::string_view > XLWorksheetNodeOrder = { // worksheet XML root node required child sequence
147
+ "sheetPr",
148
+ "dimension",
149
+ "sheetViews",
150
+ "sheetFormatPr",
151
+ "cols",
152
+ "sheetData",
153
+ "sheetCalcPr",
154
+ "sheetProtection",
155
+ "protectedRanges",
156
+ "scenarios",
157
+ "autoFilter",
158
+ "sortState",
159
+ "dataConsolidate",
160
+ "customSheetViews",
161
+ "mergeCells",
162
+ "phoneticPr",
163
+ "conditionalFormatting",
164
+ "dataValidations",
165
+ "hyperlinks",
166
+ "printOptions",
167
+ "pageMargins",
168
+ "pageSetup",
169
+ "headerFooter",
170
+ "rowBreaks",
171
+ "colBreaks",
172
+ "customProperties",
173
+ "cellWatches",
174
+ "ignoredErrors",
175
+ "smartTags",
176
+ "drawing",
177
+ "legacyDrawing",
178
+ "legacyDrawingHF",
179
+ "picture",
180
+ "oleObjects",
181
+ "controls",
182
+ "webPublishItems",
183
+ "tableParts",
184
+ "extLst"
185
+ }; // END: const std::vector< std::string_view > XLWorksheetNodeOrder
186
+
187
+ // ================================================================================
188
+ // Converter functions between OpenXLSX class specific enum class types and OOXML values
189
+ // ================================================================================
190
+ OPENXLSX_EXPORT XLCfType XLCfTypeFromString (std::string const& typeString );
191
+ OPENXLSX_EXPORT std::string XLCfTypeToString (XLCfType cfType );
192
+ OPENXLSX_EXPORT XLCfOperator XLCfOperatorFromString (std::string const& operatorString );
193
+ OPENXLSX_EXPORT std::string XLCfOperatorToString (XLCfOperator cfOperator );
194
+ OPENXLSX_EXPORT XLCfTimePeriod XLCfTimePeriodFromString(std::string const& timePeriodString);
195
+ OPENXLSX_EXPORT std::string XLCfTimePeriodToString (XLCfTimePeriod cfTimePeriod );
196
+
197
+ /**
198
+ * @brief The XLSheetBase class is the base class for the XLWorksheet and XLChartsheet classes. However,
199
+ * it is not a base class in the traditional sense. Rather, it provides common functionality that is
200
+ * inherited via the CRTP (Curiously Recurring Template Pattern) pattern.
201
+ * @tparam T Type that will inherit functionality. Restricted to types XLWorksheet and XLChartsheet.
202
+ */
203
+ template<typename T, typename = std::enable_if_t<std::is_same_v<T, XLWorksheet> || std::is_same_v<T, XLChartsheet>>>
204
+ class OPENXLSX_EXPORT XLSheetBase : public XLXmlFile
205
+ {
206
+ public:
207
+ /**
208
+ * @brief Constructor
209
+ */
210
+ XLSheetBase() : XLXmlFile(nullptr) {};
211
+
212
+ /**
213
+ * @brief The constructor. There are no default constructor, so all parameters must be provided for
214
+ * constructing an XLAbstractSheet object. Since this is a pure abstract class, instantiation is only
215
+ * possible via one of the derived classes.
216
+ * @param xmlData
217
+ */
218
+ explicit XLSheetBase(XLXmlData* xmlData) : XLXmlFile(xmlData) {}
219
+
220
+ /**
221
+ * @brief The copy constructor.
222
+ * @param other The object to be copied.
223
+ * @note The default copy constructor is used, i.e. only shallow copying of pointer data members.
224
+ */
225
+ XLSheetBase(const XLSheetBase& other) = default;
226
+
227
+ /**
228
+ * @brief
229
+ * @param other
230
+ */
231
+ XLSheetBase(XLSheetBase&& other) noexcept = default;
232
+
233
+ /**
234
+ * @brief The destructor
235
+ * @note The default destructor is used, since cleanup of pointer data members is not required.
236
+ */
237
+ ~XLSheetBase() = default;
238
+
239
+ /**
240
+ * @brief Assignment operator
241
+ * @return A reference to the new object.
242
+ * @note The default assignment operator is used, i.e. only shallow copying of pointer data members.
243
+ */
244
+ XLSheetBase& operator=(const XLSheetBase&) = default;
245
+
246
+ /**
247
+ * @brief
248
+ * @param other
249
+ * @return
250
+ */
251
+ XLSheetBase& operator=(XLSheetBase&& other) noexcept = default;
252
+
253
+ /**
254
+ * @brief
255
+ * @return
256
+ */
257
+ XLSheetState visibility() const
258
+ {
259
+ XLQuery query(XLQueryType::QuerySheetVisibility);
260
+ query.setParam("sheetID", relationshipID());
261
+ const auto state = parentDoc().execQuery(query).template result<std::string>();
262
+ auto result = XLSheetState::Visible;
263
+
264
+ if (state == "visible" || state.empty()) {
265
+ result = XLSheetState::Visible;
266
+ }
267
+ else if (state == "hidden") {
268
+ result = XLSheetState::Hidden;
269
+ }
270
+ else if (state == "veryHidden") {
271
+ result = XLSheetState::VeryHidden;
272
+ }
273
+
274
+ return result;
275
+ }
276
+
277
+ /**
278
+ * @brief
279
+ * @param state
280
+ */
281
+ void setVisibility(XLSheetState state)
282
+ {
283
+ auto stateString = std::string();
284
+ switch (state) {
285
+ case XLSheetState::Visible:
286
+ stateString = "visible";
287
+ break;
288
+
289
+ case XLSheetState::Hidden:
290
+ stateString = "hidden";
291
+ break;
292
+
293
+ case XLSheetState::VeryHidden:
294
+ stateString = "veryHidden";
295
+ break;
296
+ }
297
+
298
+ parentDoc().execCommand(XLCommand(XLCommandType::SetSheetVisibility)
299
+ .setParam("sheetID", relationshipID())
300
+ .setParam("sheetVisibility", stateString));
301
+ }
302
+
303
+ /**
304
+ * @brief
305
+ * @return
306
+ * @todo To be implemented.
307
+ */
308
+ XLColor color() const
309
+ {
310
+ return static_cast<const T&>(*this).getColor_impl();
311
+ }
312
+
313
+ /**
314
+ * @brief
315
+ * @param color
316
+ */
317
+ void setColor(const XLColor& color)
318
+ {
319
+ static_cast<T&>(*this).setColor_impl(color);
320
+ }
321
+
322
+ /**
323
+ * @brief look up sheet name via relationshipID, then attempt to match that to a sheet in XLWorkbook::sheet(uint16_t index), looping over index
324
+ * @return the index by which the sheet could be accessed from XLWorkbook::sheet
325
+ */
326
+ uint16_t index() const
327
+ {
328
+ XLQuery query(XLQueryType::QuerySheetIndex);
329
+ query.setParam("sheetID", relationshipID());
330
+ return static_cast<uint16_t>(std::stoi(parentDoc().execQuery(query).template result<std::string>()));
331
+ }
332
+
333
+ /**
334
+ * @brief
335
+ * @param index
336
+ */
337
+ void setIndex(uint16_t index)
338
+ {
339
+ parentDoc().execCommand(XLCommand(XLCommandType::SetSheetIndex)
340
+ .setParam("sheetID", relationshipID())
341
+ .setParam("sheetIndex", index));
342
+ }
343
+
344
+ /**
345
+ * @brief Method to retrieve the name of the sheet.
346
+ * @return A std::string with the sheet name.
347
+ */
348
+ std::string name() const
349
+ {
350
+ XLQuery query(XLQueryType::QuerySheetName);
351
+ query.setParam("sheetID", relationshipID());
352
+ return parentDoc().execQuery(query).template result<std::string>();
353
+ }
354
+
355
+ /**
356
+ * @brief Method for renaming the sheet.
357
+ * @param sheetName A std::string with the new name.
358
+ */
359
+ void setName(const std::string& sheetName)
360
+ {
361
+ parentDoc().execCommand(XLCommand(XLCommandType::SetSheetName)
362
+ .setParam("sheetID", relationshipID())
363
+ .setParam("sheetName", name())
364
+ .setParam("newName", sheetName));
365
+ }
366
+
367
+ /**
368
+ * @brief
369
+ * @return
370
+ */
371
+ bool isSelected() const
372
+ {
373
+ return static_cast<const T&>(*this).isSelected_impl();
374
+ }
375
+
376
+ /**
377
+ * @brief
378
+ * @param selected
379
+ */
380
+ void setSelected(bool selected)
381
+ {
382
+ static_cast<T&>(*this).setSelected_impl(selected);
383
+ }
384
+
385
+ /**
386
+ * @brief
387
+ * @return
388
+ */
389
+ bool isActive() const
390
+ {
391
+ return static_cast<const T&>(*this).isActive_impl();
392
+ }
393
+
394
+ /**
395
+ * @brief
396
+ */
397
+ bool setActive()
398
+ {
399
+ return static_cast<T&>(*this).setActive_impl();
400
+ }
401
+
402
+ /**
403
+ * @brief Method for cloning the sheet.
404
+ * @param newName A std::string with the name of the clone
405
+ * @return A pointer to the cloned object.
406
+ * @note This is a pure abstract method. I.e. it is implemented in subclasses.
407
+ */
408
+ void clone(const std::string& newName)
409
+ {
410
+ parentDoc().execCommand(XLCommand(XLCommandType::CloneSheet)
411
+ .setParam("sheetID", relationshipID())
412
+ .setParam("cloneName", newName));
413
+ }
414
+
415
+ private: // ---------- Private Member Variables ---------- //
416
+ };
417
+
418
+
419
+ // ================================================================================
420
+ // XLConditionalFormats Class
421
+ // ================================================================================
422
+
423
+ /**
424
+ * @brief An encapsulation of a cfRule item
425
+ */
426
+ class OPENXLSX_EXPORT XLCfRule
427
+ {
428
+ friend class XLCfRules; // for access to m_cfRuleNode in XLCfRules::create
429
+ public: // ---------- Public Member Functions ---------- //
430
+ /**
431
+ * @brief
432
+ */
433
+ XLCfRule();
434
+
435
+ /**
436
+ * @brief Constructor. New items should only be created through an XLCfRules object.
437
+ * @param node An XMLNode object with the <cfRule> item. If no input is provided, a null node is used.
438
+ */
439
+ explicit XLCfRule(const XMLNode& node);
440
+
441
+ /**
442
+ * @brief Copy Constructor.
443
+ * @param other Object to be copied.
444
+ */
445
+ XLCfRule(const XLCfRule& other);
446
+
447
+ /**
448
+ * @brief Move Constructor.
449
+ * @param other Object to be moved.
450
+ */
451
+ XLCfRule(XLCfRule&& other) noexcept;
452
+
453
+ /**
454
+ * @brief
455
+ */
456
+ ~XLCfRule();
457
+
458
+ /**
459
+ * @brief Copy assignment operator.
460
+ * @param other Right hand side of assignment operation.
461
+ * @return A reference to the lhs object.
462
+ */
463
+ XLCfRule& operator=(const XLCfRule& other);
464
+
465
+ /**
466
+ * @brief Move assignment operator.
467
+ * @param other Right hand side of assignment operation.
468
+ * @return A reference to lhs object.
469
+ */
470
+ XLCfRule& operator=(XLCfRule&& other) noexcept;
471
+
472
+ /**
473
+ * @brief Test if this is an empty node
474
+ * @return true if underlying XMLNode is empty
475
+ */
476
+ bool empty() const;
477
+
478
+ /**
479
+ * @brief Element getter functions
480
+ */
481
+ std::string formula() const;
482
+ XLUnsupportedElement colorScale() const;
483
+ XLUnsupportedElement dataBar() const;
484
+ XLUnsupportedElement iconSet() const;
485
+ XLUnsupportedElement extLst() const;
486
+
487
+ /**
488
+ * @brief Attribute getter functions
489
+ */
490
+
491
+ XLCfType type() const;
492
+ XLStyleIndex dxfId() const;
493
+ uint16_t priority() const; // >= 1
494
+ bool stopIfTrue() const; // default: false
495
+ bool aboveAverage() const; // default: true
496
+ bool percent() const; // default: false
497
+ bool bottom() const; // default: false
498
+ XLCfOperator Operator() const; // Valid only when @type = cellIs
499
+ std::string text() const; // The text value in a "text contains" conditional formatting rule. Valid only for @type = containsText.
500
+ XLCfTimePeriod timePeriod() const; // The applicable time period in a "date occurring..." conditional formatting rule. Valid only for @type = timePeriod.
501
+ uint16_t rank() const; // The value of "n" in a "top/bottom n" conditional formatting rule. Valid only for @type = top10.
502
+ int16_t stdDev() const; // The number of standard deviations to include above or below the average in the conditional formatting rule. Valid only for @type = aboveAverage
503
+ bool equalAverage() const; // default: false. Flag indicating whether the 'aboveAverage' and 'belowAverage' criteria
504
+ // is inclusive of the average itself, or exclusive of that value. '1' indicates to include
505
+ // the average value in the criteria. Valid only for @type = aboveAverage.
506
+
507
+ /**
508
+ * @brief Element setter functions
509
+ */
510
+ bool setFormula (std::string const& newFormula);
511
+ bool setColorScale(XLUnsupportedElement const& newColorScale); // unsupported
512
+ bool setDataBar (XLUnsupportedElement const& newDataBar ); // unsupported
513
+ bool setIconSet (XLUnsupportedElement const& newIconSet ); // unsupported
514
+ bool setExtLst (XLUnsupportedElement const& newExtLst ); // unsupported
515
+
516
+ /**
517
+ * @brief Attribute setter functions
518
+ */
519
+ bool setType(XLCfType newType);
520
+ bool setDxfId(XLStyleIndex newDxfId);
521
+ private: // Protect setPriority from access by any but the parent XLCfRules class
522
+ bool setPriority(uint16_t newPriority); // internal function, user access through XLCfRules::setPriority
523
+ public:
524
+ bool setStopIfTrue(bool set = true);
525
+ bool setAboveAverage(bool set = true);
526
+ bool setPercent(bool set = true);
527
+ bool setBottom(bool set = true);
528
+ bool setOperator(XLCfOperator newOperator);
529
+ bool setText(std::string const& newText);
530
+ bool setTimePeriod(XLCfTimePeriod newTimePeriod);
531
+ bool setRank(uint16_t newRank);
532
+ bool setStdDev(int16_t newStdDev);
533
+ bool setEqualAverage(bool set = true);
534
+
535
+ /**
536
+ * @brief Return a string summary of the cfRule properties
537
+ * @return string with info about the cfRule object
538
+ */
539
+ std::string summary() const;
540
+
541
+ private: // ---------- Private Member Variables ---------- //
542
+ std::unique_ptr<XMLNode> m_cfRuleNode; /**< An XMLNode object with the conditional formatting item */
543
+ inline static const std::vector< std::string_view > m_nodeOrder = { // cfRule XML node required child sequence
544
+ "formula", // TODO: maxOccurs = 3!
545
+ "colorScale",
546
+ "dataBar",
547
+ "iconSet",
548
+ "extLst"
549
+ };
550
+ };
551
+
552
+
553
+ constexpr const char * XLDefaultCfRulePrefix = "\n\t\t"; // indentation to use for newly created cfRule nodes
554
+ /**
555
+ * @brief An encapsulation of a conditional formatting rules item
556
+ */
557
+ class OPENXLSX_EXPORT XLCfRules
558
+ {
559
+ public:
560
+ /**
561
+ * @brief
562
+ */
563
+ XLCfRules();
564
+
565
+ /**
566
+ * @brief Constructor. New items should only be created through an XLConditionalFormat object.
567
+ * @param node An XMLNode object with the conditionalFormatting item. If no input is provided, a null node is used.
568
+ */
569
+ explicit XLCfRules(const XMLNode& node);
570
+
571
+ /**
572
+ * @brief Copy Constructor.
573
+ * @param other Object to be copied.
574
+ */
575
+ XLCfRules(const XLCfRules& other);
576
+
577
+ /**
578
+ * @brief Move Constructor.
579
+ * @param other Object to be moved.
580
+ */
581
+ XLCfRules(XLCfRules&& other) noexcept;
582
+
583
+ /**
584
+ * @brief
585
+ */
586
+ ~XLCfRules();
587
+
588
+ /**
589
+ * @brief Copy assignment operator.
590
+ * @param other Right hand side of assignment operation.
591
+ * @return A reference to the lhs object.
592
+ */
593
+ XLCfRules& operator=(const XLCfRules& other);
594
+
595
+ /**
596
+ * @brief Move assignment operator.
597
+ * @param other Right hand side of assignment operation.
598
+ * @return A reference to lhs object.
599
+ */
600
+ XLCfRules& operator=(XLCfRules&& other) noexcept;
601
+
602
+ /**
603
+ * @brief Test if this is an empty node
604
+ * @return true if underlying XMLNode is empty
605
+ */
606
+ bool empty() const;
607
+
608
+ /**
609
+ * @brief Get the count highest priority value currently in use by a rule
610
+ * @return The highest value that a cfRule has set for attribute priority
611
+ */
612
+ uint16_t maxPriorityValue() const;
613
+
614
+ /**
615
+ * @brief Provide a duplication-free interface to setting rule priorities: if a newPriority value exists, increment all existing priorities >= newPriority by 1
616
+ * @param cfRuleIndex the index of the rule for which to set the priority
617
+ * @param newPriority the priority value to assign
618
+ * @return true on success, false if ruleIndex does not exist
619
+ */
620
+ bool setPriority(size_t cfRuleIndex, uint16_t newPriority);
621
+
622
+ /**
623
+ * @brief Renumber all existing rule priorities to a clean sequence in steps of increment
624
+ * @param increment increase the priority value by this much between rules
625
+ */
626
+ void renumberPriorities(uint16_t increment = 1);
627
+
628
+ /**
629
+ * @brief Get the count of rules for this conditional formatting
630
+ * @return The amount of <cfRule> nodes in the <conditionalFormatting> node
631
+ */
632
+ size_t count() const;
633
+
634
+ /**
635
+ * @brief Get the conditional format identified by index
636
+ * @return An XLCfRule object
637
+ */
638
+ XLCfRule cfRuleByIndex(size_t index) const;
639
+
640
+ /**
641
+ * @brief Operator overload: allow [] as shortcut access to cfRuleByIndex
642
+ * @param index The index within the XML sequence
643
+ * @return An XLCfRule object
644
+ */
645
+ XLCfRule operator[](size_t index) const { return cfRuleByIndex(index); }
646
+
647
+ /**
648
+ * @brief Append a new XLCfRule, based on copyFrom, and return its index in the <conditionalFormatting> list of <cfRule> entries
649
+ * @param copyFrom Can provide an XLCfRule to use as template for the new condition
650
+ * @param conditionalFormattingPrefix Prefix the newly created conditionalFormatting XMLNode with this pugi::node_pcdata text
651
+ * @returns The index of the new conditional formatting as used by operator[]
652
+ */
653
+ size_t create(XLCfRule copyFrom = XLCfRule{}, std::string cfRulePrefix = XLDefaultCfRulePrefix);
654
+
655
+ /**
656
+ * @brief Return a string summary of the conditional formatting rules properties
657
+ * @return string with info about the conditional formatting rules object
658
+ */
659
+ std::string summary() const;
660
+
661
+ private: // ---------- Private Member Variables ---------- //
662
+ std::unique_ptr<XMLNode> m_conditionalFormattingNode; /**< An XMLNode object with the conditional formatting item */
663
+ // TODO: pass in m_nodeOrder from XLConditionalFormat
664
+ inline static const std::vector< std::string_view > m_nodeOrder = { // conditionalFormatting XML node required child sequence
665
+ "cfRule",
666
+ "extLst"
667
+ };
668
+ };
669
+
670
+
671
+ /**
672
+ * @brief An encapsulation of a conditional formatting item
673
+ */
674
+ class OPENXLSX_EXPORT XLConditionalFormat
675
+ {
676
+ friend class XLConditionalFormats; // for access to m_conditionalFormattingNode in XLConditionalFormats::create
677
+ public: // ---------- Public Member Functions ---------- //
678
+ /**
679
+ * @brief
680
+ */
681
+ XLConditionalFormat();
682
+
683
+ /**
684
+ * @brief Constructor. New items should only be created through an XLWorksheet object.
685
+ * @param node An XMLNode object with the conditionalFormatting item. If no input is provided, a null node is used.
686
+ */
687
+ explicit XLConditionalFormat(const XMLNode& node);
688
+
689
+ /**
690
+ * @brief Copy Constructor.
691
+ * @param other Object to be copied.
692
+ */
693
+ XLConditionalFormat(const XLConditionalFormat& other);
694
+
695
+ /**
696
+ * @brief Move Constructor.
697
+ * @param other Object to be moved.
698
+ */
699
+ XLConditionalFormat(XLConditionalFormat&& other) noexcept;
700
+
701
+ /**
702
+ * @brief
703
+ */
704
+ ~XLConditionalFormat();
705
+
706
+ /**
707
+ * @brief Copy assignment operator.
708
+ * @param other Right hand side of assignment operation.
709
+ * @return A reference to the lhs object.
710
+ */
711
+ XLConditionalFormat& operator=(const XLConditionalFormat& other);
712
+
713
+ /**
714
+ * @brief Move assignment operator.
715
+ * @param other Right hand side of assignment operation.
716
+ * @return A reference to lhs object.
717
+ */
718
+ XLConditionalFormat& operator=(XLConditionalFormat&& other) noexcept;
719
+
720
+ /**
721
+ * @brief Test if this is an empty node
722
+ * @return true if underlying XMLNode is empty
723
+ */
724
+ bool empty() const;
725
+
726
+ /**
727
+ * @brief Get the sqref property - the range over which these conditional formatting rules apply
728
+ * @return string of the sqref property
729
+ */
730
+ std::string sqref() const;
731
+
732
+ /**
733
+ * @brief Get the conditional formatting rules to be applied to sqref
734
+ * @return the conditional formatting rules applicable to sqref
735
+ */
736
+ XLCfRules cfRules() const;
737
+
738
+
739
+ /**
740
+ * @brief Unsupported getter
741
+ */
742
+ XLUnsupportedElement extLst() const { return XLUnsupportedElement{}; } // <conditionalFormatting><extLst>...</extLst></conditionalFormatting>
743
+
744
+ /**
745
+ * @brief Setter functions for conditional formatting parameters
746
+ * @param value that shall be set
747
+ * @return true for success, false for failure
748
+ */
749
+ bool setSqref (std::string newSqref);
750
+
751
+ /**
752
+ * @brief Unsupported setter
753
+ */
754
+ bool setExtLst (XLUnsupportedElement const& newExtLst);
755
+
756
+ /**
757
+ * @brief Return a string summary of the conditional format properties
758
+ * @return string with info about the conditional formatting object
759
+ */
760
+ std::string summary() const;
761
+
762
+ private: // ---------- Private Member Variables ---------- //
763
+ std::unique_ptr<XMLNode> m_conditionalFormattingNode; /**< An XMLNode object with the conditional formatting item */
764
+ inline static const std::vector< std::string_view > m_nodeOrder = { // conditionalFormatting XML node required child sequence
765
+ "cfRule",
766
+ "extLst"
767
+ };
768
+ };
769
+
770
+
771
+ constexpr const char * XLDefaultConditionalFormattingPrefix = "\n\t"; // indentation to use for newly created conditional formatting nodes
772
+ /**
773
+ * @brief An encapsulation of the XLSX conditional formats
774
+ */
775
+ class OPENXLSX_EXPORT XLConditionalFormats
776
+ {
777
+ public: // ---------- Public Member Functions ---------- //
778
+ /**
779
+ * @brief
780
+ */
781
+ XLConditionalFormats();
782
+
783
+ /**
784
+ * @brief Constructor. New items should only be created through an XLWorksheet object.
785
+ * @param node An XMLNode object with the worksheet root node. Required to access / manipulate any conditional formats
786
+ */
787
+ explicit XLConditionalFormats(const XMLNode& node);
788
+
789
+ /**
790
+ * @brief Copy Constructor.
791
+ * @param other Object to be copied.
792
+ */
793
+ XLConditionalFormats(const XLConditionalFormats& other);
794
+
795
+ /**
796
+ * @brief Move Constructor.
797
+ * @param other Object to be moved.
798
+ */
799
+ XLConditionalFormats(XLConditionalFormats&& other);
800
+
801
+ /**
802
+ * @brief
803
+ */
804
+ ~XLConditionalFormats();
805
+
806
+ /**
807
+ * @brief Copy assignment operator.
808
+ * @param other Right hand side of assignment operation.
809
+ * @return A reference to the lhs object.
810
+ */
811
+ XLConditionalFormats& operator=(const XLConditionalFormats& other);
812
+
813
+ /**
814
+ * @brief Move assignment operator.
815
+ * @param other Right hand side of assignment operation.
816
+ * @return A reference to lhs object.
817
+ */
818
+ XLConditionalFormats& operator=(XLConditionalFormats&& other) noexcept;
819
+
820
+ /**
821
+ * @brief Test if this is an empty node
822
+ * @return true if underlying XMLNode is empty
823
+ */
824
+ bool empty() const;
825
+
826
+ /**
827
+ * @brief Get the count of conditional formatting settings
828
+ * @return The amount of <conditionalFormatting> nodes in the worksheet
829
+ */
830
+ size_t count() const;
831
+
832
+ /**
833
+ * @brief Get the conditional format identified by index
834
+ * @return An XLConditionalFormat object
835
+ */
836
+ XLConditionalFormat conditionalFormatByIndex(size_t index) const;
837
+
838
+ /**
839
+ * @brief Operator overload: allow [] as shortcut access to conditionalFormatByIndex
840
+ * @param index The index within the XML sequence
841
+ * @return An XLConditionalFormat object
842
+ */
843
+ XLConditionalFormat operator[](size_t index) const { return conditionalFormatByIndex(index); }
844
+
845
+ /**
846
+ * @brief Append a new XLConditionalFormat, based on copyFrom, and return its index in the worksheet's conditional formats
847
+ * @param copyFrom Can provide an XLConditionalFormat to use as template for the new condition
848
+ * @param conditionalFormattingPrefix Prefix the newly created conditionalFormatting XMLNode with this pugi::node_pcdata text
849
+ * @returns The index of the new conditional formatting as used by operator[]
850
+ */
851
+ size_t create(XLConditionalFormat copyFrom = XLConditionalFormat{}, std::string conditionalFormattingPrefix = XLDefaultConditionalFormattingPrefix);
852
+
853
+ /**
854
+ * @brief Return a string summary of the conditional formattings properties
855
+ * @return string with info about the conditional formattings object
856
+ */
857
+ std::string summary() const;
858
+
859
+ private: // ---------- Private Member Variables ---------- //
860
+ std::unique_ptr<XMLNode> m_sheetNode; /**< An XMLNode object with the sheet item */
861
+ const std::vector< std::string_view >& m_nodeOrder = XLWorksheetNodeOrder; // worksheet XML root node required child sequence
862
+ };
863
+
864
+ /**
865
+ * @brief A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook object.
866
+ */
867
+ class OPENXLSX_EXPORT XLWorksheet final : public XLSheetBase<XLWorksheet>
868
+ {
869
+ friend class XLCell;
870
+ friend class XLRow;
871
+ friend class XLWorkbook;
872
+ friend class XLSheetBase<XLWorksheet>;
873
+
874
+ //----------------------------------------------------------------------------------------------------------------------
875
+ // Public Member Functions
876
+ //----------------------------------------------------------------------------------------------------------------------
877
+
878
+ public:
879
+ /**
880
+ * @brief Default constructor
881
+ */
882
+ XLWorksheet() : XLSheetBase(nullptr) {};
883
+
884
+ /**
885
+ * @brief
886
+ * @param xmlData
887
+ */
888
+ explicit XLWorksheet(XLXmlData* xmlData);
889
+
890
+ /**
891
+ * @brief Copy Constructor.
892
+ * @warning Use comments() and vmlDrawing() with extreme caution: the underlying XLVmlDrawing class manages the last assigned shape id, and *will* create invalid XML
893
+ * if two separate variables are used to create VML drawings or comments within the same worksheet
894
+ */
895
+ XLWorksheet(const XLWorksheet& other);
896
+
897
+ /**
898
+ * @brief Move Constructor.
899
+ */
900
+ XLWorksheet(XLWorksheet&& other);
901
+
902
+ /**
903
+ * @brief Destructor.
904
+ */
905
+ ~XLWorksheet();
906
+
907
+ /**
908
+ * @brief Copy assignment operator.
909
+ * @warning Use comments() and vmlDrawing() with extreme caution: the underlying XLVmlDrawing class manages the last assigned shape id, and *will* create invalid XML
910
+ * if two separate variables are used to create VML drawings or comments within the same worksheet
911
+ */
912
+ XLWorksheet& operator=(const XLWorksheet& other);
913
+
914
+ /**
915
+ * @brief Move assignment operator.
916
+ */
917
+ XLWorksheet& operator=(XLWorksheet&& other);
918
+
919
+ /**
920
+ * @brief
921
+ * @param ref
922
+ * @return
923
+ */
924
+ XLCellAssignable cell(const std::string& ref) const;
925
+
926
+ /**
927
+ * @brief Get an XLCell object for the given cell reference.
928
+ * @param ref An XLCellReference object with the address of the cell to get.
929
+ * @return A reference to the requested XLCell object.
930
+ */
931
+ XLCellAssignable cell(const XLCellReference& ref) const;
932
+
933
+ /**
934
+ * @brief Get the cell at the given coordinates. Create row & cell XML if missing.
935
+ * @param rowNumber The row number (index base 1).
936
+ * @param columnNumber The column number (index base 1).
937
+ * @return A reference to the XLCell object at the given coordinates.
938
+ */
939
+ XLCellAssignable cell(uint32_t rowNumber, uint16_t columnNumber) const;
940
+
941
+ /**
942
+ * @brief overload for findCell(uint32_t rowNumber, uint16_t columnNumber)
943
+ * @param ref string with the address of the cell to find
944
+ * @return
945
+ */
946
+ XLCellAssignable findCell(const std::string& ref) const;
947
+
948
+ /**
949
+ * @brief overload for findCell(uint32_t rowNumber, uint16_t columnNumber)
950
+ * @param ref An XLCellReference object with the address of the cell to find
951
+ * @return
952
+ */
953
+ XLCellAssignable findCell(const XLCellReference& ref) const;
954
+
955
+ /**
956
+ * @brief Find the cell at the given coordinates. Do *not* create row & cell XML if missing and return an empty XLCellAssignable instead
957
+ * @param rowNumber The row number (index base 1).
958
+ * @param columnNumber The column number (index base 1).
959
+ * @return A reference to the XLCell object at the given coordinates or an empty XLCell object
960
+ * @note Must test (XLCell::empty() == false) before accessing any other methods of the returned object.
961
+ * @warning This is a usability feature with bad performance. When testing a large amounts of cells or working with large worksheets,
962
+ * it is better to use an XLCellIterator with the cell range of interest.
963
+ */
964
+ XLCellAssignable findCell(uint32_t rowNumber, uint16_t columnNumber) const;
965
+
966
+ /**
967
+ * @brief Set the worksheet's <dimension> tag, attribute ref
968
+ * @param topLeft top left cell for the dimension tag. If left empty, will use A1
969
+ * @param bottomRight bottom right cell to use for the dimension tag. If left empty, or equivalent "A1", will use lastCell()
970
+ * @param autoCalculateLastCell if false, disables auto-calculation of last cell for bottomRight
971
+ * @note if bottomRight is "A1", invoke lastCell to determine dimension range - can be disabled by passing XLDoNotCalculateLastCell for autoCalculateLastCell
972
+ * @note serves as root function for two overloads
973
+ * @warning for now, invoking a new XLWorksheet constructor will delete the <dimension> tag again (preferring no tag over a wrong one). This function should only be invoked directly before a save operation.
974
+ * @return
975
+ */
976
+ void setDimension(XLCellReference topLeft = XLCellReference("A1"), XLCellReference bottomRight = XLCellReference{}, bool autoCalculateLastCell = XLCalculateLastCell);
977
+
978
+ /**
979
+ * @brief overload for setDimension(XLCellReference topLeft, XLCellReference bottomRight)
980
+ * @param topLeft address of the top left cell for dimension
981
+ * @param bottomRight address of the bottom right cell for dimension
982
+ * @note as in the root setDimension function, providing "A1" for bottomRight invokes auto-calculation of last cell
983
+ * @warning see root setDimension function
984
+ * @return
985
+ */
986
+ void setDimension(std::string topLeft, std::string bottomRight);
987
+
988
+ /**
989
+ * @brief overload for setDimension(XLCellReference topLeft, XLCellReference bottomRight)
990
+ * @param dimension range address to use as dimension
991
+ * @note while setting "A1:A1" still allows auto-calculation of last cell, this overload also allows setting a *single* dimension "A1", by invoking the root setDimension function with XLDoNotCalculateLastCell
992
+ * @warning see root setDimension function
993
+ * @return
994
+ */
995
+ void setDimension(std::string dimension);
996
+
997
+ /**
998
+ * @brief Get a range for the area currently in use (i.e. from cell A1 to the last cell being in use).
999
+ * @return An XLCellRange object with the entire range.
1000
+ */
1001
+ XLCellRange range() const;
1002
+
1003
+ /**
1004
+ * @brief Get a range with the given coordinates.
1005
+ * @param topLeft An XLCellReference object with the coordinates to the top left cell.
1006
+ * @param bottomRight An XLCellReference object with the coordinates to the bottom right cell.
1007
+ * @return An XLCellRange object with the requested range.
1008
+ */
1009
+ XLCellRange range(const XLCellReference& topLeft, const XLCellReference& bottomRight) const;
1010
+
1011
+ /**
1012
+ * @brief Get a range with the given coordinates.
1013
+ * @param topLeft A std::string that is convertible to an XLCellReference to the top left cell
1014
+ * @param bottomRight A std::string that is convertible to an XLCellReference to the bottom right cell.
1015
+ * @return An XLCellRange object with the requested range.
1016
+ */
1017
+ XLCellRange range(std::string const& topLeft, std::string const& bottomRight) const;
1018
+
1019
+ /**
1020
+ * @brief Get a range with the given coordinates.
1021
+ * @param rangeReference A std::string that contains two XLCellReferences separated by a delimiter ':'
1022
+ * Example "A2:B5"
1023
+ * @return An XLCellRange object with the requested range.
1024
+ */
1025
+ XLCellRange range(std::string const& rangeReference) const;
1026
+
1027
+ /**
1028
+ * @brief
1029
+ * @return
1030
+ */
1031
+ XLRowRange rows() const;
1032
+
1033
+ /**
1034
+ * @brief
1035
+ * @param rowCount
1036
+ * @return
1037
+ */
1038
+ XLRowRange rows(uint32_t rowCount) const;
1039
+
1040
+ /**
1041
+ * @brief
1042
+ * @param firstRow
1043
+ * @param lastRow
1044
+ * @return
1045
+ */
1046
+ XLRowRange rows(uint32_t firstRow, uint32_t lastRow) const;
1047
+
1048
+ /**
1049
+ * @brief Get the row with the given row number.
1050
+ * @param rowNumber The number of the row to retrieve.
1051
+ * @return A reference to the XLRow object.
1052
+ */
1053
+ XLRow row(uint32_t rowNumber) const;
1054
+
1055
+ /**
1056
+ * @brief Get the column with the given column number.
1057
+ * @param columnNumber The number of the column to retrieve.
1058
+ * @return A reference to the XLColumn object.
1059
+ */
1060
+ XLColumn column(uint16_t columnNumber) const;
1061
+
1062
+ /**
1063
+ * @brief Get the column with the given column reference
1064
+ * @param columnRef The letters referencing the given column
1065
+ * @return A reference to the XLColumn object.
1066
+ */
1067
+ XLColumn column(std::string const& columnRef) const;
1068
+
1069
+ /**
1070
+ * @brief Get an XLCellReference to the last (bottom right) cell in the worksheet.
1071
+ * @return An XLCellReference for the last cell.
1072
+ */
1073
+ XLCellReference lastCell() const noexcept;
1074
+
1075
+ /**
1076
+ * @brief Get the number of columns in the worksheet.
1077
+ * @return The number of columns.
1078
+ */
1079
+ uint16_t columnCount() const noexcept;
1080
+
1081
+ /**
1082
+ * @brief Get the number of rows in the worksheet.
1083
+ * @return The number of rows.
1084
+ */
1085
+ uint32_t rowCount() const noexcept;
1086
+
1087
+ /**
1088
+ * @brief Delete the row with the given row number from the underlying OOXML.
1089
+ * @return true if a row entry existed in OOXML & was deleted, otherwise false
1090
+ * @warning this will break all existing references to that row (formulas etc)
1091
+ */
1092
+ bool deleteRow(uint32_t rowNumber);
1093
+
1094
+ /**
1095
+ * @brief
1096
+ * @param oldName
1097
+ * @param newName
1098
+ */
1099
+ void updateSheetName(const std::string& oldName, const std::string& newName);
1100
+
1101
+ /**
1102
+ * @brief get an XLMergeCells object to directly access the member functions
1103
+ * @returns an XLMergeCells object for this worksheet
1104
+ */
1105
+ XLMergeCells & merges();
1106
+
1107
+ /**
1108
+ * @brief merge the cells indicated by range
1109
+ * @param rangeToMerge the XLCellRange to merge, can be obtained from XLWorksheet::range functions
1110
+ * @param emptyHiddenCells if true (XLEmptyHiddenCells), the values of hidden cells will be deleted
1111
+ * (only from the cells, not from the shared strings table, if used)
1112
+ * @throws XLInputException if range comprises < 2 cells or any cell within rangeToMerge is already part of an existing range
1113
+ */
1114
+ void mergeCells(XLCellRange const& rangeToMerge, bool emptyHiddenCells = false);
1115
+ /**
1116
+ * @brief Convenience wrapper for mergeCells with a std::string range reference
1117
+ * @param rangeReference A range reference string for the cells to merge
1118
+ * @param emptyHiddenCells as above
1119
+ */
1120
+ void mergeCells(const std::string& rangeReference, bool emptyHiddenCells = false);
1121
+
1122
+ /**
1123
+ * @brief remove the merge setting for the indicated range
1124
+ * @param rangeToUnmerge the XLCellRange to unmerge, can be obtained from XLWorksheet::range functions
1125
+ * @throws XLInputException if no merged range exists that matches rangeToMerge precisely
1126
+ */
1127
+ void unmergeCells(XLCellRange const& rangeToUnmerge);
1128
+ /**
1129
+ * @brief Convenience wrapper for unmergeCells with a std::string range reference
1130
+ * @param rangeReference A range reference string for the cells to unmerge
1131
+ */
1132
+ void unmergeCells(const std::string& rangeReference);
1133
+
1134
+ /**
1135
+ * @brief Get the array index of xl/styles.xml:<styleSheet>:<cellXfs> for the style assigned to a column.
1136
+ * This value is stored in the col attributes like so: style="2"
1137
+ * @param column The column letter(s) or index (1-based)
1138
+ * @returns The index of the applicable format style
1139
+ */
1140
+ XLStyleIndex getColumnFormat(uint16_t column) const;
1141
+ XLStyleIndex getColumnFormat(const std::string& column) const;
1142
+
1143
+ /**
1144
+ * @brief set the column style as a reference to the array index of xl/styles.xml:<styleSheet>:<cellXfs>
1145
+ * Subsequently, set the same style for all existing(!) cells in that column
1146
+ * @param column the column letter(s) or index (1-based)
1147
+ * @param cellFormatIndex the style to set, corresponding to the index of XLStyles::cellStyles()
1148
+ * @returns true on success, false on failure
1149
+ */
1150
+ bool setColumnFormat(uint16_t column, XLStyleIndex cellFormatIndex);
1151
+ bool setColumnFormat(const std::string& column, XLStyleIndex cellFormatIndex);
1152
+
1153
+ /**
1154
+ * @brief get the array index of xl/styles.xml:<styleSheet>:<cellXfs> for the style assigned to a row
1155
+ * this value is stored in the row attributes like so: s="2"
1156
+ * @param row the row index (1-based)
1157
+ * @returns the index of the applicable format style
1158
+ */
1159
+ XLStyleIndex getRowFormat(uint16_t row) const;
1160
+
1161
+ /**
1162
+ * @brief set the row style as a reference to the array index of xl/styles.xml:<styleSheet>:<cellXfs>
1163
+ * Subsequently, set the same style for all existing(!) cells in that row
1164
+ * @param row the row index (1-based)
1165
+ * @param cellFormatIndex the style to set, corresponding to the index of XLStyles::cellStyles()
1166
+ * @returns true on success, false on failure
1167
+ */
1168
+ bool setRowFormat(uint32_t row, XLStyleIndex cellFormatIndex);
1169
+
1170
+ /**
1171
+ * @brief Get the conditional formats object
1172
+ * @return An XLConditionalFormats object
1173
+ */
1174
+ XLConditionalFormats conditionalFormats() const;
1175
+
1176
+ /**
1177
+ * @brief Set the <sheetProtection> attributes sheet, objects and scenarios respectively
1178
+ * @return true upon success, false in case of any failure
1179
+ */
1180
+ bool protectSheet(bool set = true);
1181
+ bool protectObjects(bool set = true);
1182
+ bool protectScenarios(bool set = true);
1183
+
1184
+ /**
1185
+ * @brief Set the XML properties that allow the according modification of the worksheet
1186
+ * @param set if true, action will be allowed despite sheet protection, if false, action will be denied / protected
1187
+ * @note #1 default for all (if attribute is not present) is "true" = the action is protected / not allowed
1188
+ * @note #2 none of the sheet protection settings have any effect if protectSheet is not set
1189
+ * @note (library internal) counter-intuitively, the underlying bool attributes need to be set to "false" to "disable protection" for these actions
1190
+ */
1191
+ bool allowInsertColumns(bool set = true); // default: not allowed in a protected worksheet
1192
+ bool allowInsertRows(bool set = true); // " : "
1193
+ bool allowDeleteColumns(bool set = true); // " : "
1194
+ bool allowDeleteRows(bool set = true); // " : "
1195
+ bool allowSelectLockedCells(bool set = true); // default: allowed in a protected worksheet
1196
+ bool allowSelectUnlockedCells(bool set = true); // " : "
1197
+ /**
1198
+ * @brief Convenience shortcuts for allow<*>( false );
1199
+ */
1200
+ bool denyInsertColumns() { return allowInsertColumns (false); }
1201
+ bool denyInsertRows() { return allowInsertRows (false); }
1202
+ bool denyDeleteColumns() { return allowDeleteColumns (false); }
1203
+ bool denyDeleteRows() { return allowDeleteRows (false); }
1204
+ bool denySelectLockedCells() { return allowSelectLockedCells (false); }
1205
+ bool denySelectUnlockedCells() { return allowSelectUnlockedCells(false); }
1206
+
1207
+ /**
1208
+ * @brief Set the sheetProtection password attribute
1209
+ * @param hash directly stores a password hash to the password attribute, for use cases where the password shall not be used in clear text in the API
1210
+ * @note ExcelPasswordHash or ExcelPasswordHashAsString (defined in XLDocument header) can be used to calculate the hash
1211
+ * @note an empty password hash can be used to clear any password protection
1212
+ * @return true upon success, false in case of any failure
1213
+ */
1214
+ bool setPasswordHash(std::string hash);
1215
+
1216
+ /**
1217
+ * @brief Set the sheetProtection password attribute
1218
+ * @param password the XLSX password hash for this string will be stored in the password attribute
1219
+ * @note an empty password clears the password attribute
1220
+ * @return true upon success, false in case of any failure
1221
+ */
1222
+ bool setPassword(std::string password);
1223
+
1224
+ /**
1225
+ * @brief Clear the sheetProtection password attribute
1226
+ */
1227
+ bool clearPassword();
1228
+
1229
+ /**
1230
+ * @brief Clear the sheetProtection completely
1231
+ */
1232
+ bool clearSheetProtection();
1233
+
1234
+ /**
1235
+ * @brief getter functions for sheet protection settings
1236
+ * @return true if setting is "action allowed"
1237
+ */
1238
+ bool sheetProtected() const;
1239
+ bool objectsProtected() const;
1240
+ bool scenariosProtected() const;
1241
+
1242
+ /**
1243
+ * @brief getter functions for detailed sheet protections
1244
+ * @note none of the sheet protection settings have any effect if protectSheet is not set
1245
+ */
1246
+ bool insertColumnsAllowed() const;
1247
+ bool insertRowsAllowed() const;
1248
+ bool deleteColumnsAllowed() const;
1249
+ bool deleteRowsAllowed() const;
1250
+ bool selectLockedCellsAllowed() const;
1251
+ bool selectUnlockedCellsAllowed() const;
1252
+
1253
+ /**
1254
+ * @brief get sheet password hash
1255
+ */
1256
+ std::string passwordHash() const;
1257
+ /**
1258
+ * @brief check sheet password protection
1259
+ */
1260
+ bool passwordIsSet() const;
1261
+
1262
+ /**
1263
+ * @brief assemble a string summary about the sheet protection settings
1264
+ */
1265
+ std::string sheetProtectionSummary() const;
1266
+
1267
+ /**
1268
+ * @brief test whether a worksheet relationships XML file exists for this worksheet
1269
+ */
1270
+ bool hasRelationships() const;
1271
+
1272
+ /**
1273
+ * @brief test whether a VML drawing XML file exists for this worksheet
1274
+ */
1275
+ bool hasVmlDrawing() const;
1276
+
1277
+ /**
1278
+ * @brief test whether a comments XML file exists for this worksheet
1279
+ */
1280
+ bool hasComments() const;
1281
+
1282
+ /**
1283
+ * @brief test whether a tables XML file exists for this worksheet
1284
+ */
1285
+ bool hasTables() const;
1286
+
1287
+ /**
1288
+ * @brief fetch a reference to the worksheet VML drawing object
1289
+ */
1290
+ XLVmlDrawing& vmlDrawing();
1291
+
1292
+ /**
1293
+ * @brief fetch a reference to the worksheet comments
1294
+ */
1295
+ XLComments& comments();
1296
+
1297
+ /**
1298
+ * @brief fetch a reference to the worksheet tables
1299
+ */
1300
+ XLTables& tables();
1301
+
1302
+ private:
1303
+
1304
+ /**
1305
+ * @brief fetch the # number from the xml path xl/worksheets/sheet#.xml
1306
+ */
1307
+ uint16_t sheetXmlNumber() const;
1308
+
1309
+ /**
1310
+ * @brief fetch a reference to the worksheet relationships
1311
+ * @note private because transparent to the user
1312
+ */
1313
+ XLRelationships& relationships();
1314
+
1315
+ /**
1316
+ * @brief
1317
+ * @return
1318
+ */
1319
+ XLColor getColor_impl() const;
1320
+
1321
+ /**
1322
+ * @brief
1323
+ * @param color
1324
+ */
1325
+ void setColor_impl(const XLColor& color);
1326
+
1327
+ /**
1328
+ * @brief
1329
+ * @return
1330
+ */
1331
+ bool isSelected_impl() const;
1332
+
1333
+ /**
1334
+ * @brief
1335
+ * @param selected
1336
+ */
1337
+ void setSelected_impl(bool selected);
1338
+
1339
+ /**
1340
+ * @brief
1341
+ * @return
1342
+ */
1343
+ bool isActive_impl() const;
1344
+
1345
+ /**
1346
+ * @brief
1347
+ */
1348
+ bool setActive_impl();
1349
+
1350
+ private: // ---------- Private Member Variables ---------- //
1351
+ XLRelationships m_relationships{}; /**< class handling the worksheet relationships */
1352
+ XLMergeCells m_merges{}; /**< class handling the <mergeCells> */
1353
+ XLVmlDrawing m_vmlDrawing{}; /**< class handling the worksheet VML drawing object */
1354
+ XLComments m_comments{}; /**< class handling the worksheet comments */
1355
+ XLTables m_tables{}; /**< class handling the worksheet table settings */
1356
+ const std::vector< std::string_view >& m_nodeOrder = XLWorksheetNodeOrder; // worksheet XML root node required child sequence
1357
+ };
1358
+
1359
+ /**
1360
+ * @brief Class representing the an Excel chartsheet.
1361
+ * @todo This class is largely unimplemented and works just as a placeholder.
1362
+ */
1363
+ class OPENXLSX_EXPORT XLChartsheet final : public XLSheetBase<XLChartsheet>
1364
+ {
1365
+ friend class XLSheetBase<XLChartsheet>;
1366
+
1367
+ //----------------------------------------------------------------------------------------------------------------------
1368
+ // Public Member Functions
1369
+ //----------------------------------------------------------------------------------------------------------------------
1370
+
1371
+ public:
1372
+ /**
1373
+ * @brief Default constructor
1374
+ */
1375
+ XLChartsheet() : XLSheetBase(nullptr) {};
1376
+
1377
+ /**
1378
+ * @brief Constructor
1379
+ * @param xmlData
1380
+ */
1381
+ explicit XLChartsheet(XLXmlData* xmlData);
1382
+
1383
+ /**
1384
+ * @brief Copy constructor
1385
+ * @param other
1386
+ */
1387
+ XLChartsheet(const XLChartsheet& other);
1388
+
1389
+ /**
1390
+ * @brief Move constructor
1391
+ * @param other
1392
+ */
1393
+ XLChartsheet(XLChartsheet&& other) noexcept;
1394
+
1395
+ /**
1396
+ * @brief Destructor
1397
+ */
1398
+ ~XLChartsheet();
1399
+
1400
+ /**
1401
+ * @brief Copy assignment operator
1402
+ * @return
1403
+ */
1404
+ XLChartsheet& operator=(const XLChartsheet& other);
1405
+
1406
+ /**
1407
+ * @brief Move assignment operator
1408
+ * @param other
1409
+ * @return
1410
+ */
1411
+ XLChartsheet& operator=(XLChartsheet&& other) noexcept;
1412
+
1413
+ private:
1414
+
1415
+ /**
1416
+ * @brief
1417
+ * @return
1418
+ */
1419
+ XLColor getColor_impl() const;
1420
+
1421
+ /**
1422
+ * @brief
1423
+ * @param color
1424
+ */
1425
+ void setColor_impl(const XLColor& color);
1426
+
1427
+ /**
1428
+ * @brief
1429
+ * @return
1430
+ */
1431
+ bool isSelected_impl() const;
1432
+
1433
+ /**
1434
+ * @brief
1435
+ * @param selected
1436
+ */
1437
+ void setSelected_impl(bool selected);
1438
+
1439
+ /**
1440
+ * @brief test issue #316 resolution
1441
+ */
1442
+ bool isActive_impl() const { return false; } // TODO: implement actual function body, if possible for chartsheets
1443
+
1444
+ /**
1445
+ * @brief test issue #316 resolution
1446
+ */
1447
+ bool setActive_impl() { return true; } // TODO: implement actual function body, if possible for chartsheets
1448
+
1449
+ private: // ---------- Private Member Variables ---------- //
1450
+ };
1451
+
1452
+ /**
1453
+ * @brief The XLAbstractSheet is a generalized sheet class, which functions as superclass for specialized classes,
1454
+ * such as XLWorksheet. It implements functionality common to all sheet types. This is a pure abstract class,
1455
+ * so it cannot be instantiated.
1456
+ */
1457
+ class OPENXLSX_EXPORT XLSheet final : public XLXmlFile
1458
+ {
1459
+ public:
1460
+ /**
1461
+ * @brief The constructor. There are no default constructor, so all parameters must be provided for
1462
+ * constructing an XLAbstractSheet object. Since this is a pure abstract class, instantiation is only
1463
+ * possible via one of the derived classes.
1464
+ * @param xmlData
1465
+ */
1466
+ explicit XLSheet(XLXmlData* xmlData);
1467
+
1468
+ /**
1469
+ * @brief Copy constructor.
1470
+ * @param other The object to be copied.
1471
+ * @note The default copy constructor is used, i.e. only shallow copying of pointer data members.
1472
+ */
1473
+ XLSheet(const XLSheet& other);
1474
+
1475
+ /**
1476
+ * @brief Move constructor
1477
+ * @param other
1478
+ */
1479
+ XLSheet(XLSheet&& other) noexcept;
1480
+
1481
+ /**
1482
+ * @brief The destructor
1483
+ * @note The default destructor is used, since cleanup of pointer data members is not required.
1484
+ */
1485
+ ~XLSheet();
1486
+
1487
+ /**
1488
+ * @brief Copy assignment operator
1489
+ * @return A reference to the new object.
1490
+ * @note The default assignment operator is used, i.e. only shallow copying of pointer data members.
1491
+ */
1492
+ XLSheet& operator=(const XLSheet& other);
1493
+
1494
+ /**
1495
+ * @brief Move assignment operator
1496
+ * @param other
1497
+ * @return
1498
+ */
1499
+ XLSheet& operator=(XLSheet&& other) noexcept;
1500
+
1501
+ /**
1502
+ * @brief Method for getting the current visibility state of the sheet.
1503
+ * @return An XLSheetState enum object, with the current sheet state.
1504
+ */
1505
+ XLSheetState visibility() const;
1506
+
1507
+ /**
1508
+ * @brief Method for setting the state of the sheet.
1509
+ * @param state An XLSheetState enum object with the new state.
1510
+ * @bug For some reason, this method doesn't work. The data is written correctly to the xml file, but the sheet
1511
+ * is not hidden when opening the file in Excel.
1512
+ */
1513
+ void setVisibility(XLSheetState state);
1514
+
1515
+ /**
1516
+ * @brief
1517
+ * @return
1518
+ */
1519
+ XLColor color() const;
1520
+
1521
+ /**
1522
+ * @brief
1523
+ * @param color
1524
+ */
1525
+ void setColor(const XLColor& color);
1526
+
1527
+ /**
1528
+ * @brief Method for getting the index of the sheet.
1529
+ * @return An int with the index of the sheet.
1530
+ */
1531
+ uint16_t index() const;
1532
+
1533
+ /**
1534
+ * @brief Method for setting the index of the sheet. This effectively moves the sheet to a different position.
1535
+ */
1536
+ void setIndex(uint16_t index);
1537
+
1538
+ /**
1539
+ * @brief Method to retrieve the name of the sheet.
1540
+ * @return A std::string with the sheet name.
1541
+ */
1542
+ std::string name() const;
1543
+
1544
+ /**
1545
+ * @brief Method for renaming the sheet.
1546
+ * @param name A std::string with the new name.
1547
+ */
1548
+ void setName(const std::string& name);
1549
+
1550
+ /**
1551
+ * @brief Determine whether the sheet is selected
1552
+ * @return
1553
+ */
1554
+ bool isSelected() const;
1555
+
1556
+ /**
1557
+ * @brief
1558
+ * @param selected
1559
+ */
1560
+ void setSelected(bool selected);
1561
+
1562
+ /**
1563
+ * @brief
1564
+ * @return
1565
+ */
1566
+ bool isActive() const;
1567
+
1568
+ /**
1569
+ * @brief
1570
+ */
1571
+ bool setActive();
1572
+
1573
+ /**
1574
+ * @brief Method to get the type of the sheet.
1575
+ * @return An XLSheetType enum object with the sheet type.
1576
+ */
1577
+ template<
1578
+ typename SheetType,
1579
+ typename = std::enable_if_t<std::is_same_v<SheetType, XLWorksheet> || std::is_same_v<SheetType, XLChartsheet>>>
1580
+ bool isType() const
1581
+ {
1582
+ return std::holds_alternative<SheetType>(m_sheet);
1583
+ }
1584
+
1585
+ /**
1586
+ * @brief Method for cloning the sheet.
1587
+ * @param newName A std::string with the name of the clone
1588
+ * @return A pointer to the cloned object.
1589
+ * @note This is a pure abstract method. I.e. it is implemented in subclasses.
1590
+ */
1591
+ void clone(const std::string& newName);
1592
+
1593
+ /**
1594
+ * @brief
1595
+ * @tparam T
1596
+ * @return
1597
+ */
1598
+ template<typename T, typename = std::enable_if_t<std::is_same_v<T, XLWorksheet> || std::is_same_v<T, XLChartsheet>>>
1599
+ T get() const
1600
+ {
1601
+ try {
1602
+ if constexpr (std::is_same<T, XLWorksheet>::value)
1603
+ return std::get<XLWorksheet>(m_sheet);
1604
+
1605
+ else if constexpr (std::is_same<T, XLChartsheet>::value)
1606
+ return std::get<XLChartsheet>(m_sheet);
1607
+ }
1608
+
1609
+ catch (const std::bad_variant_access&) {
1610
+ throw XLSheetError("XLSheet object does not contain the requested sheet type.");
1611
+ }
1612
+ }
1613
+
1614
+ /**
1615
+ * @brief
1616
+ * @return
1617
+ */
1618
+ operator XLWorksheet() const; // NOLINT
1619
+
1620
+ /**
1621
+ * @brief
1622
+ * @return
1623
+ */
1624
+ operator XLChartsheet() const; // NOLINT
1625
+
1626
+ /**
1627
+ * @brief Print the XML contents of the XLSheet using the underlying XMLNode print function
1628
+ */
1629
+ void print(std::basic_ostream<char>& ostr) const;
1630
+
1631
+ private: // ---------- Private Member Variables ---------- //
1632
+ std::variant<XLWorksheet, XLChartsheet> m_sheet; /**< */
1633
+ };
1634
+ } // namespace OpenXLSX
1635
+
1636
+ #ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
1637
+ # pragma warning(pop)
1638
+ #endif // _MSC_VER
1639
+
1640
+ #endif // OPENXLSX_XLSHEET_HPP