OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLCellValue.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_XLCELLVALUE_HPP
12#define OPENXLSX_XLCELLVALUE_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 <cmath>
22#include <cstdint>
23#include <fast_float/fast_float.h>
24#include <fmt/base.h>
25#include <fmt/format.h>
26#include <iostream>
27#include <string>
28#include <variant>
29
30// ===== OpenXLSX Includes ===== //
31#include "OpenXLSX-Exports.hpp"
32#include "XLDateTime.hpp"
33#include "XLException.hpp"
34#include "XLRichText.hpp"
35#include "XLXmlParser.hpp"
36
37typedef std::variant<std::string, int64_t, double, bool, OpenXLSX::XLRichText> XLCellValueType;
38
39namespace OpenXLSX
40{
41 class XLCellValueProxy;
42 class XLCell;
43
48
49 //---------- Private Struct to enable XLValueType conversion to double ---------- //
51 {
52 std::string packageName = "VisitXLCellValueTypeToDouble";
53 double operator()(int64_t v) const { return static_cast<double>(v); }
54 double operator()(double v) const { return v; }
55 double operator()(bool v) const { return v; }
56 // double operator()( struct timestamp v ) { /* to be implemented if this type ever gets supported */ }
57 double operator()([[maybe_unused]] const OpenXLSX::XLRichText& v) const
58 {
59 throw XLValueTypeError("RichText is not convertible to double.");
60 return 0.0;
61 }
62 double operator()(std::string v) const
63 {
64 throw XLValueTypeError(
65 "string is not convertible to double."); // disable if implicit conversion of string to double shall be allowed
66 double val;
67 auto [ptr, ec] = fast_float::from_chars(v.data(), v.data() + v.size(), val);
68 if (ec != std::errc()) throw XLValueTypeError("string is not convertible to double.");
69 return val;
70 }
71 };
72
73 //---------- Private Struct to enable XLValueType conversion to std::string ---------- //
75 {
76 std::string packageName = "VisitXLCellValueTypeToString";
77 std::string operator()(int64_t v) const { return fmt::format("{}", v); }
78 std::string operator()(double v) const { return fmt::format("{}", v); }
79 std::string operator()(bool v) const { return v ? "true" : "false"; }
80 // std::string operator()( struct timestamp v ) { return timestampString( v.seconds, v.microseconds, WITH_MS ); }
81 std::string operator()(const XLRichText& v) const { return v.plainText(); }
82 std::string operator()(std::string v) const { return v; }
83 };
84
88 class OPENXLSX_EXPORT XLCellValue
89 {
90 friend class XLCellValueProxy; // to allow access to m_value
91
92 // Comparison operators between XLCellValue objects
93 friend bool operator==(const XLCellValue& lhs, const XLCellValue& rhs);
94 friend bool operator!=(const XLCellValue& lhs, const XLCellValue& rhs);
95 friend bool operator<(const XLCellValue& lhs, const XLCellValue& rhs);
96 friend bool operator>(const XLCellValue& lhs, const XLCellValue& rhs);
97 friend bool operator<=(const XLCellValue& lhs, const XLCellValue& rhs);
98 friend bool operator>=(const XLCellValue& lhs, const XLCellValue& rhs);
99 friend std::ostream& operator<<(std::ostream& os, const XLCellValue& value);
100 friend std::hash<OpenXLSX::XLCellValue>;
101
102#define OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP(OP, FUNCTOR) \
103 friend bool operator OP(const XLCellValue& lhs, std::string_view rhs) \
104 { \
105 if (std::holds_alternative<std::string>(lhs.m_value)) \
106 return FUNCTOR<>{}(std::string_view(std::get<std::string>(lhs.m_value)), rhs); \
107 return false; \
108 } \
109 friend bool operator OP(std::string_view lhs, const XLCellValue& rhs) \
110 { \
111 if (std::holds_alternative<std::string>(rhs.m_value)) \
112 return FUNCTOR<>{}(lhs, std::string_view(std::get<std::string>(rhs.m_value))); \
113 return false; \
114 } \
115 friend bool operator OP(const XLCellValue& lhs, const char* rhs) { return lhs OP std::string_view(rhs); } \
116 friend bool operator OP(const char* lhs, const XLCellValue& rhs) { return std::string_view(lhs) OP rhs; } \
117 friend bool operator OP(const XLCellValue& lhs, const std::string& rhs) { return lhs OP std::string_view(rhs); } \
118 friend bool operator OP(const std::string& lhs, const XLCellValue& rhs) { return std::string_view(lhs) OP rhs; }
119
121 OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP(!=, std::not_equal_to)
124 OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP(<=, std::less_equal)
125 OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP(>=, std::greater_equal)
126
127#undef OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP
128
129 public:
134
141 template<typename T,
142 typename = std::enable_if_t<
143 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
144 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
145 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
146 XLCellValue(const T& value) // NOLINT
147 {
148 // ===== If the argument is a bool, set the m_type attribute to Boolean.
149 if constexpr (std::is_integral_v<T> and std::is_same_v<T, bool>) {
150 m_type = XLValueType::Boolean;
151 m_value = value;
152 }
153
154 // ===== If the argument is an integral type, set the m_type attribute to Integer.
155 else if constexpr (std::is_integral_v<T> and !std::is_same_v<T, bool>) {
156 m_type = XLValueType::Integer;
157 m_value = static_cast<int64_t>(value);
158 }
159
160 // ===== If the argument is a string type (i.e. is constructable from *char),
161 // ===== set the m_type attribute to String.
162 else if constexpr (std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> ||
163 std::is_same_v<std::decay_t<T>, const char*> ||
164 (std::is_same_v<std::decay_t<T>, char*> and !std::is_same_v<T, bool>))
165 {
166 m_type = XLValueType::String;
167 m_value = std::string(value);
168 }
169
170 // ===== If the argument is an XLDateTime, set the value to the date/time serial number.
171 else if constexpr (std::is_same_v<T, XLDateTime>) {
172 m_type = XLValueType::Float;
173 m_value = value.serial();
174 }
175
176 // ===== If the argument is an XLRichText, set the m_type attribute to RichText.
177 else if constexpr (std::is_same_v<T, XLRichText>) {
178 m_type = XLValueType::RichText;
179 m_value = value;
180 }
181
182 // ===== If the argument is a floating point type, set the m_type attribute to Float.
183 // ===== If not, a static_assert will result in compilation error.
184 else {
185 static_assert(std::is_floating_point_v<T>, "Invalid argument for constructing XLCellValue object");
186 if (std::isfinite(value)) {
187 m_type = XLValueType::Float;
188 m_value = static_cast<double>(value);
189 }
190 else {
191 m_type = XLValueType::Error;
192 m_value = std::string("#NUM!");
193 }
194 }
195 }
196
202
207 XLCellValue(XLCellValue&& other) noexcept;
208
213
220
227
234 template<typename T,
235 typename = std::enable_if_t<
236 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
237 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
238 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
240 {
241 // ===== Implemented using copy-and-swap.
242 XLCellValue temp(value);
243 std::swap(*this, temp);
244 return *this;
245 }
246
252 template<
253 typename T,
254 typename = std::enable_if_t<std::is_same_v<T, XLCellValue> or std::is_integral_v<T> or std::is_floating_point_v<T> ||
255 std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> ||
256 std::is_same_v<std::decay_t<T>, const char*> or std::is_same_v<std::decay_t<T>, char*> ||
257 std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
258 void set(T numberValue)
259 {
260 // ===== Implemented using the assignment operator.
261 *this = numberValue;
262 }
263
270 template<typename T,
271 typename = std::enable_if_t<
272 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
273 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
274 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLDateTime> or std::is_same_v<T, OpenXLSX::XLRichText>>>
275 T get() const
276 {
277 try {
278 return privateGet<T>();
279 }
280
281 catch (const std::bad_variant_access&) {
282 throw XLValueTypeError("XLCellValue object does not contain the requested type.");
283 }
284 }
285
286 private:
294 template<typename T,
295 typename = std::enable_if_t<
296 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
297 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
298 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
299 T privateGet() const
300 {
301 try {
302 if constexpr (std::is_integral_v<T> and std::is_same_v<T, bool>) return std::get<bool>(m_value);
303
304 if constexpr (std::is_integral_v<T> and !std::is_same_v<T, bool>) return static_cast<T>(std::get<int64_t>(m_value));
305
306 if constexpr (std::is_floating_point_v<T>) {
307 return static_cast<T>(getDouble()); // 2025-01-10: allow implicit conversion of int and bool to double (string
308 // conversion disabled for now)
309 // if (m_type == XLValueType::Error) return static_cast<T>(std::nan("1"));
310 // return static_cast<T>(std::get<double>(m_value));
311 }
312
313 if constexpr (std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> ||
314 std::is_same_v<std::decay_t<T>, const char*> ||
315 (std::is_same_v<std::decay_t<T>, char*> and !std::is_same_v<T, bool>))
316 return std::get<std::string>(m_value).c_str();
317
318 if constexpr (std::is_same_v<T, OpenXLSX::XLRichText>) return std::get<OpenXLSX::XLRichText>(m_value);
319
320 if constexpr (std::is_same_v<T, XLDateTime>)
321 return XLDateTime(getDouble()); // 2025-01-10: allow implicit conversion of int and bool to double (string conversion
322 // disabled for now)
323 }
324
325 catch (const std::bad_variant_access&) {
326 throw XLValueTypeError("XLCellValue object does not contain the requested type.");
327 }
328 }
329
330 public:
336 double getDouble() const
337 {
338 if (m_type == XLValueType::Error) return static_cast<double>(std::nan("1"));
339 try {
340 return std::visit(VisitXLCellValueTypeToDouble(), m_value);
341 }
342 catch (...) {
343 throw XLValueTypeError("XLCellValue object is not convertible to double.");
344 }
345 }
346
352 std::string getString() // pull request #158 is covered by this
353 {
354 try {
355 return std::visit(VisitXLCellValueTypeToString(), m_value);
356 }
357 catch (...) { // 2024-05-27: was catch( string s ) - must have been a typo, currently nothing throws a string here
358 throw XLValueTypeError("XLCellValue object is not convertible to string.");
359 }
360 }
361
366 const XLCellValueType& getVariant() const // pull request #127
367 { return m_value; }
368
375 template<typename T,
376 typename = std::enable_if_t<
377 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
378 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
379 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
380 operator T() const
381 { return this->get<T>(); }
382
387 XLCellValue& clear();
388
393 XLCellValue& setError(const std::string& error);
394
399 XLValueType type() const;
400
405 const char* typeAsString() const;
406
407 private:
408 XLCellValueType m_value{std::string("")};
409 XLValueType m_type{XLValueType::Empty};
410 };
411
417 class OPENXLSX_EXPORT XLCellValueProxy
418 {
419 friend class XLCell;
420 friend class XLCellValue;
421 friend class XLDocument; // for reindexing shared strings
422
423 public:
428
434 XLCellValueProxy& operator=(const XLCellValueProxy& other);
435
442 template<typename T,
443 typename = std::enable_if_t<
444 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
445 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
446 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLCellValue> or std::is_same_v<T, XLDateTime> or
447 std::is_same_v<T, OpenXLSX::XLRichText>>>
448 XLCellValueProxy& operator=(const T& value)
449 { // NOLINT
450
451 if constexpr (std::is_integral_v<T> and std::is_same_v<T, bool>) // if bool
452 setBoolean(value);
453
454 else if constexpr (std::is_integral_v<T> and !std::is_same_v<T, bool>) // if integer
455 setInteger(value);
456
457 else if constexpr (std::is_floating_point_v<T>) // if floating point
458 setFloat(value);
459
460 else if constexpr (std::is_same_v<T, XLDateTime>)
461 setFloat(value.serial());
462
463 else if constexpr (std::is_same_v<T, OpenXLSX::XLRichText>)
464 setRichText(value);
465
466 else if constexpr (std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> ||
467 std::is_same_v<std::decay_t<T>, const char*> ||
468 (std::is_same_v<std::decay_t<T>, char*> and !std::is_same_v<T, bool> and !std::is_same_v<T, XLCellValue>))
469 {
470 setString(value);
471 }
472
473 if constexpr (std::is_same_v<T, XLCellValue>) {
474 switch (value.type()) {
476 setBoolean(value.template get<bool>());
477 break;
479 setInteger(value.template get<int64_t>());
480 break;
482 setFloat(value.template get<double>());
483 break;
485 setString(value.template privateGet<const char*>());
486 break;
488 setRichText(value.template get<OpenXLSX::XLRichText>());
489 break;
491 clear();
492 break;
493 default:
494 setError("#N/A");
495 break;
496 }
497 }
498
499 return *this;
500 }
501
507 template<typename T,
508 typename = std::enable_if_t<
509 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
510 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
511 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLCellValue> or std::is_same_v<T, XLDateTime> or
512 std::is_same_v<T, OpenXLSX::XLRichText>>>
513 void set(const T& value)
514 { *this = value; }
515
520 template<typename T,
521 typename = std::enable_if_t<
522 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
523 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
524 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
525 T get() const
526 {
527 if constexpr (std::is_same_v<std::decay_t<T>, std::string_view> || std::is_same_v<std::decay_t<T>, const char*>) {
528 auto view = getStringView();
529 if constexpr (std::is_same_v<std::decay_t<T>, const char*>) return view.data();
530 else return view;
531 }
532 else if constexpr (std::is_same_v<std::decay_t<T>, std::string>) {
533 return std::string(getStringView());
534 }
535 else {
536 return getValue().get<T>();
537 }
538 }
539
544 XLCellValueProxy& clear();
545
550 XLCellValueProxy& setError(const std::string& error);
551
556 XLValueType type() const;
557
562 const char* typeAsString() const;
563
568 operator XLCellValue() const; // NOLINT
569
575 template<typename T,
576 typename = std::enable_if_t<
577 std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> ||
578 std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> ||
579 std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
580 operator T() const
581 { return getValue().get<T>(); }
582
588
593 std::string_view getStringView() const;
594 std::string getString() const // pull request #158 is covered by this
595 {
596 try {
597 return std::visit(VisitXLCellValueTypeToString(), getValue().m_value);
598 }
599 catch (...) {
600 throw XLValueTypeError("XLCellValue object is not convertible to string.");
601 }
602 }
603
604 private:
610 XLCellValueProxy(XLCell* cell, XMLNode* cellNode);
611
617
622 XLCellValueProxy(XLCellValueProxy&& other) noexcept;
623
629 XLCellValueProxy& operator=(XLCellValueProxy&& other) noexcept;
630
634 void notifyDocumentOfChange();
635
640 void setInteger(int64_t numberValue);
641
646 void setBoolean(bool numberValue);
647
652 void setFloat(double numberValue);
653
658 void setString(std::string_view stringValue);
659
664 void setRichText(const XLRichText& richTextValue);
665
670 XLCellValue getValue() const;
671
677 int32_t stringIndex() const;
678
684 bool setStringIndex(int32_t newIndex);
685 XLCell* m_cell;
686 XMLNode* m_cellNode;
687 };
688
689} // namespace OpenXLSX
690
691#include <functional>
692
693namespace OpenXLSX
694{
695 // Utility for cross-type comparison
696 template<typename Op>
698 {
699 template<typename T, typename U>
700 bool operator()(const T& lhs, const U& rhs) const
701 {
702 if constexpr (std::is_arithmetic_v<T> && std::is_arithmetic_v<U> && !std::is_same_v<T, bool> && !std::is_same_v<U, bool>) {
703 return Op{}(lhs, rhs);
704 }
705 else if constexpr (std::is_same_v<T, bool> && std::is_same_v<U, bool>) {
706 return Op{}(lhs, rhs);
707 }
708 else if constexpr (std::is_same_v<T, std::string> && std::is_same_v<U, std::string>) {
709 return Op{}(lhs, rhs);
710 }
711 else {
712 return false;
713 }
714 }
715 };
716
721 inline bool operator==(const XLCellValue& lhs, const XLCellValue& rhs)
722 { return std::visit(XLCompareVisitor<std::equal_to<>>{}, lhs.m_value, rhs.m_value); }
723
728 inline bool operator!=(const XLCellValue& lhs, const XLCellValue& rhs)
729 { return std::visit(XLCompareVisitor<std::not_equal_to<>>{}, lhs.m_value, rhs.m_value); }
730
735 inline bool operator<(const XLCellValue& lhs, const XLCellValue& rhs)
736 { return std::visit(XLCompareVisitor<std::less<>>{}, lhs.m_value, rhs.m_value); }
737
742 inline bool operator>(const XLCellValue& lhs, const XLCellValue& rhs)
743 { return std::visit(XLCompareVisitor<std::greater<>>{}, lhs.m_value, rhs.m_value); }
744
749 inline bool operator<=(const XLCellValue& lhs, const XLCellValue& rhs)
750 { return std::visit(XLCompareVisitor<std::less_equal<>>{}, lhs.m_value, rhs.m_value); }
751
756 inline bool operator>=(const XLCellValue& lhs, const XLCellValue& rhs)
757 { return std::visit(XLCompareVisitor<std::greater_equal<>>{}, lhs.m_value, rhs.m_value); }
758
763 inline std::ostream& operator<<(std::ostream& os, const XLCellValue& value)
764 {
765 switch (value.type()) {
767 return os << "";
769 return os << value.get<bool>();
771 return os << value.get<int64_t>();
773 return os << value.get<double>();
775 return os << value.get<std::string>(); // 2025-01-10 BUGFIX: for temporary value objects, this was undefined behavior due
776 // to returning a string_view
778 return os << value.get<OpenXLSX::XLRichText>().plainText();
779 default:
780 return os << "";
781 }
782 }
783
784 inline std::ostream& operator<<(std::ostream& os, const XLCellValueProxy& value)
785 {
786 switch (value.type()) {
788 return os << "";
790 return os << value.get<bool>();
792 return os << value.get<int64_t>();
794 return os << value.get<double>();
796 return os << value.get<std::string>(); // 2025-01-10 BUGFIX: for temporary value objects, this was undefined behavior due
797 // to returning a string_view
799 return os << value.getString(); // getString() for proxy calls VisitXLCellValueTypeToString which handles RichText
800 default:
801 return os << "";
802 }
803 }
804
805} // namespace OpenXLSX
806
807namespace std
808{
809 template<>
810 struct hash<OpenXLSX::XLRichTextRun>
811 {
812 std::size_t operator()(const OpenXLSX::XLRichTextRun& run) const noexcept
813 {
814 std::size_t h = std::hash<std::string>{}(run.text());
815 if (run.bold()) h ^= std::hash<bool>{}(*run.bold()) + 0x9e3779b9 + (h << 6) + (h >> 2);
816 if (run.italic()) h ^= std::hash<bool>{}(*run.italic()) + 0x9e3779b9 + (h << 6) + (h >> 2);
817 return h;
818 }
819 };
820
821 template<>
822 struct hash<OpenXLSX::XLRichText>
823 {
824 std::size_t operator()(const OpenXLSX::XLRichText& rt) const noexcept
825 {
826 std::size_t h = 0;
827 for (const auto& run : rt.runs()) { h ^= std::hash<OpenXLSX::XLRichTextRun>{}(run) + 0x9e3779b9 + (h << 6) + (h >> 2); }
828 return h;
829 }
830 };
831
832 template<>
833 struct hash<OpenXLSX::XLCellValue> // NOLINT
834 {
835 std::size_t operator()(const OpenXLSX::XLCellValue& value) const noexcept
836 {
837 return std::visit([](const auto& v) { return std::hash<std::decay_t<decltype(v)>>{}(v); }, value.getVariant());
838 }
839 };
840} // namespace std
841
842#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
843# pragma warning(pop)
844#endif // _MSC_VER
845
846#endif // OPENXLSX_XLCELLVALUE_HPP
#define OPENXLSX_XLCELLVALUE_FRIEND_STRING_OP(OP, FUNCTOR)
Definition XLCellValue.hpp:102
std::variant< std::string, int64_t, double, bool, OpenXLSX::XLRichText > XLCellValueType
Definition XLCellValue.hpp:37
The XLCellValueProxy class is used for proxy (or placeholder) objects for XLCellValue objects.
Definition XLCellValue.hpp:418
XLCellValueProxy & clear()
Clear the contents of the cell.
Definition XLCellValue.cpp:214
XLCellValueProxy & operator=(const T &value)
Templated assignment operator.
Definition XLCellValue.hpp:448
XLCellValueProxy & operator=(const XLCellValueProxy &other)
Copy assignment operator.
Definition XLCellValue.cpp:188
friend class XLDocument
Definition XLCellValue.hpp:421
friend class XLCell
Definition XLCellValue.hpp:419
XLCellValueProxy & setError(const std::string &error)
Set the cell value to a error state.
Definition XLCellValue.cpp:241
friend class XLCellValue
Definition XLCellValue.hpp:420
std::string getString() const
Definition XLCellValue.hpp:594
T get() const
Definition XLCellValue.hpp:525
std::string_view getStringView() const
get the cell value as a std::string, regardless of value type
Definition XLCellValue.cpp:704
~XLCellValueProxy()
Destructor.
void set(const T &value)
Sets the cell value using an automatically deduced type proxy.
Definition XLCellValue.hpp:513
XLValueType type() const
Get the value type for the cell.
Definition XLCellValue.cpp:273
Class encapsulating a cell value.
Definition XLCellValue.hpp:89
void set(T numberValue)
Templated setter for integral and bool types.
Definition XLCellValue.hpp:258
XLCellValue(XLCellValue &&other) noexcept
Move constructor.
double getDouble() const
get the cell value as a double, regardless of value type
Definition XLCellValue.hpp:336
XLCellValue & operator=(T value)
Templated assignment operator.
Definition XLCellValue.hpp:239
friend bool operator<(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:735
friend class XLCellValueProxy
Definition XLCellValue.hpp:90
const XLCellValueType & getVariant() const
get the cell value as a std::variant of XLCellValueType
Definition XLCellValue.hpp:366
friend bool operator==(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:721
friend std::ostream & operator<<(std::ostream &os, const XLCellValue &value)
Definition XLCellValue.hpp:763
std::string getString()
get the cell value as a std::string, regardless of value type
Definition XLCellValue.hpp:352
friend bool operator>(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:742
~XLCellValue()
Destructor.
friend bool operator<=(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:749
XLCellValue(const XLCellValue &other)
Copy constructor.
XLCellValue & operator=(const XLCellValue &other)
Copy assignment operator.
XLValueType type() const
Get the value type of the current object.
Definition XLCellValue.cpp:121
T get() const
Templated getter.
Definition XLCellValue.hpp:275
friend bool operator!=(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:728
XLCellValue(const T &value)
A templated constructor. Any value convertible to a valid cell value can be used as argument.
Definition XLCellValue.hpp:146
XLCellValue & operator=(XLCellValue &&other) noexcept
Move assignment operator.
friend bool operator>=(const XLCellValue &lhs, const XLCellValue &rhs)
Definition XLCellValue.hpp:756
XLCellValue()
Default constructor.
An implementation class encapsulating the properties and behaviours of a spreadsheet cell.
Definition XLCell.hpp:51
A class representing a single run of rich text.
Definition XLRichText.hpp:30
A class representing rich text in a cell.
Definition XLRichText.hpp:139
std::string plainText() const
Get the plain text representation of the rich text.
Definition XLRichText.hpp:160
Definition XLException.hpp:51
Definition IXLCellProvider.hpp:24
bool operator==(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:314
bool operator!=(const XLCell &lhs, const XLCell &rhs)
Definition XLCell.hpp:321
bool operator<=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially precedes or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:254
bool operator<(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Evaluates precedence primarily by row, then by column, allowing cell ranges to be sorted efficiently ...
Definition XLCellReference.hpp:243
XLValueType
Enum defining the valid value types for a an Excel spreadsheet cell.
Definition XLCellValue.hpp:47
@ Float
Definition XLCellValue.hpp:47
@ RichText
Definition XLCellValue.hpp:47
@ String
Definition XLCellValue.hpp:47
@ Boolean
Definition XLCellValue.hpp:47
@ Error
Definition XLCellValue.hpp:47
@ Integer
Definition XLCellValue.hpp:47
@ Empty
Definition XLCellValue.hpp:47
@ Error
Definition XLCalculationEngine.hpp:129
@ Empty
Definition XLCalculationEngine.hpp:130
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
bool operator>=(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Asserts whether a cell sequentially follows or occupies the exact same coordinate as another.
Definition XLCellReference.hpp:259
std::ostream & operator<<(std::ostream &os, const XLCell &c)
ostream output of XLCell content
Definition XLCell.hpp:329
bool operator>(const XLCellReference &lhs, const XLCellReference &rhs) noexcept
Inverts the less-than operator logic to verify strict left-to-right, top-to-bottom traversal dominanc...
Definition XLCellReference.hpp:249
Definition XLCellIterator.hpp:131
Definition XLCellValue.hpp:51
std::string packageName
Definition XLCellValue.hpp:52
double operator()(std::string v) const
Definition XLCellValue.hpp:62
double operator()(int64_t v) const
Definition XLCellValue.hpp:53
double operator()(double v) const
Definition XLCellValue.hpp:54
double operator()(bool v) const
Definition XLCellValue.hpp:55
double operator()(const OpenXLSX::XLRichText &v) const
Definition XLCellValue.hpp:57
Definition XLCellValue.hpp:75
std::string operator()(bool v) const
Definition XLCellValue.hpp:79
std::string operator()(int64_t v) const
Definition XLCellValue.hpp:77
std::string operator()(double v) const
Definition XLCellValue.hpp:78
std::string operator()(std::string v) const
Definition XLCellValue.hpp:82
std::string packageName
Definition XLCellValue.hpp:76
std::string operator()(const XLRichText &v) const
Definition XLCellValue.hpp:81
Definition XLCellValue.hpp:698
bool operator()(const T &lhs, const U &rhs) const
Definition XLCellValue.hpp:700
std::size_t operator()(const OpenXLSX::XLCellValue &value) const noexcept
Definition XLCellValue.hpp:835
std::size_t operator()(const OpenXLSX::XLRichTextRun &run) const noexcept
Definition XLCellValue.hpp:812
std::size_t operator()(const OpenXLSX::XLRichText &rt) const noexcept
Definition XLCellValue.hpp:824