xlnt
conditional_format.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024 xlnt-community
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE
22 //
23 // @license: http://www.opensource.org/licenses/mit-license.php
24 // @author: see AUTHORS file
25 
26 #pragma once
27 
28 #include <cstdint>
29 #include <string>
30 
31 #include <xlnt/xlnt_config.hpp>
32 #include <xlnt/utils/optional.hpp>
33 
34 namespace xlnt {
35 
36 class border;
37 class fill;
38 class font;
39 
40 namespace detail {
41 
42 struct conditional_format_impl;
43 struct stylesheet;
44 class xlsx_consumer;
45 class xlsx_producer;
46 
47 } // namespace detail
48 
49 class XLNT_API condition
50 {
51 public:
52  static condition text_starts_with(const std::string &start);
53  static condition text_ends_with(const std::string &end);
54  static condition text_contains(const std::string &start);
55  static condition text_does_not_contain(const std::string &start);
56 
57  bool operator==(const condition &rhs) const
58  {
59  return text_comparand_ == rhs.text_comparand_;
60  }
61 
62 private:
63  friend class detail::xlsx_producer;
64 
65  enum class type
66  {
67  contains_text
68  } type_;
69 
70  enum class condition_operator
71  {
72  starts_with,
73  ends_with,
74  contains,
75  does_not_contain
76  } operator_;
77 
78  std::string text_comparand_;
79 };
80 
86 class XLNT_API conditional_format
87 {
88 public:
92  conditional_format() = delete;
93 
97  conditional_format(const conditional_format &other) = default;
98 
99  // Formatting (xf) components
100 
104  bool has_border() const;
105 
109  class border border() const;
110 
114  conditional_format border(const xlnt::border &new_border);
115 
119  bool has_fill() const;
120 
124  class fill fill() const;
125 
129  conditional_format fill(const xlnt::fill &new_fill);
130 
134  bool has_font() const;
135 
139  class font font() const;
140 
144  conditional_format font(const xlnt::font &new_font);
145 
149  bool operator==(const conditional_format &other) const;
150 
154  bool operator!=(const conditional_format &other) const;
155 
156 private:
157  friend struct detail::stylesheet;
158  friend class detail::xlsx_consumer;
159 
163  conditional_format(detail::conditional_format_impl *d);
164 
168  detail::conditional_format_impl *d_;
169 };
170 
171 } // namespace xlnt
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
Describes a conditional format that will be applied to all cells in the associated range that satisfy...
Definition: conditional_format.hpp:86
Describes the font style of a particular cell.
Definition: font.hpp:41
Definition: conditional_format.hpp:49
Describes the fill style of a particular cell.
Definition: fill.hpp:299
Describes the border style of a particular cell.
Definition: border.hpp:94
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.