format.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE
  20. //
  21. // @license: http://www.opensource.org/licenses/mit-license.php
  22. // @author: see AUTHORS file
  23. #pragma once
  24. #include <cstddef>
  25. #include <string>
  26. #include <xlnt/xlnt_config.hpp>
  27. namespace xlnt {
  28. class alignment;
  29. class border;
  30. class cell;
  31. class fill;
  32. class font;
  33. class number_format;
  34. class protection;
  35. class style;
  36. template <typename T>
  37. class optional;
  38. namespace detail {
  39. struct format_impl;
  40. struct stylesheet;
  41. class xlsx_producer;
  42. class xlsx_consumer;
  43. } // namespace detail
  44. /// <summary>
  45. /// Describes the formatting of a particular cell.
  46. /// </summary>
  47. class XLNT_API format
  48. {
  49. public:
  50. /// <summary>
  51. /// Returns the alignment of this format.
  52. /// </summary>
  53. class alignment alignment() const;
  54. /// <summary>
  55. /// Sets the alignment of this format to new_alignment. Applied, which defaults
  56. /// to true, determines whether the alignment should be enabled for cells using
  57. /// this format.
  58. /// </summary>
  59. format alignment(const xlnt::alignment &new_alignment, xlnt::optional<bool> applied = {});
  60. /// <summary>
  61. /// Returns true if the alignment of this format should be applied to cells
  62. /// using it.
  63. /// </summary>
  64. bool alignment_applied() const;
  65. /// <summary>
  66. /// Returns the border of this format.
  67. /// </summary>
  68. class border border() const;
  69. /// <summary>
  70. /// Sets the border of this format to new_border. Applied, which defaults
  71. /// to true, determines whether the border should be enabled for cells using
  72. /// this format.
  73. /// </summary>
  74. format border(const xlnt::border &new_border, xlnt::optional<bool> applied = {});
  75. /// <summary>
  76. /// Returns true if the border set for this format should be applied to cells using the format.
  77. /// </summary>
  78. bool border_applied() const;
  79. /// <summary>
  80. /// Returns the fill of this format.
  81. /// </summary>
  82. class fill fill() const;
  83. /// <summary>
  84. /// Sets the fill of this format to new_fill. Applied, which defaults
  85. /// to true, determines whether the border should be enabled for cells using
  86. /// this format.
  87. /// </summary>
  88. format fill(const xlnt::fill &new_fill, xlnt::optional<bool> applied = {});
  89. /// <summary>
  90. /// Returns true if the fill set for this format should be applied to cells using the format.
  91. /// </summary>
  92. bool fill_applied() const;
  93. /// <summary>
  94. /// Returns the font of this format.
  95. /// </summary>
  96. class font font() const;
  97. /// <summary>
  98. /// Sets the font of this format to new_font. Applied, which defaults
  99. /// to true, determines whether the font should be enabled for cells using
  100. /// this format.
  101. /// </summary>
  102. format font(const xlnt::font &new_font, xlnt::optional<bool> applied = {});
  103. /// <summary>
  104. /// Returns true if the font set for this format should be applied to cells using the format.
  105. /// </summary>
  106. bool font_applied() const;
  107. /// <summary>
  108. /// Returns the number format of this format.
  109. /// </summary>
  110. class number_format number_format() const;
  111. /// <summary>
  112. /// Sets the number format of this format to new_number_format. Applied, which defaults
  113. /// to true, determines whether the number format should be enabled for cells using
  114. /// this format.
  115. /// </summary>
  116. format number_format(const xlnt::number_format &new_number_format, xlnt::optional<bool> applied = {});
  117. /// <summary>
  118. /// Returns true if the number_format set for this format should be applied to cells using the format.
  119. /// </summary>
  120. bool number_format_applied() const;
  121. /// <summary>
  122. /// Returns the protection of this format.
  123. /// </summary>
  124. class protection protection() const;
  125. /// <summary>
  126. /// Returns true if the protection set for this format should be applied to cells using the format.
  127. /// </summary>
  128. bool protection_applied() const;
  129. /// <summary>
  130. /// Sets the protection of this format to new_protection. Applied, which defaults
  131. /// to true, determines whether the protection should be enabled for cells using
  132. /// this format.
  133. /// </summary>
  134. format protection(const xlnt::protection &new_protection, xlnt::optional<bool> applied = {});
  135. /// <summary>
  136. /// Returns true if the pivot table interface is enabled for this format.
  137. /// </summary>
  138. bool pivot_button() const;
  139. /// <summary>
  140. /// If show is true, a pivot table interface will be displayed for cells using
  141. /// this format.
  142. /// </summary>
  143. void pivot_button(bool show);
  144. /// <summary>
  145. /// Returns true if this format should add a single-quote prefix for all text values.
  146. /// </summary>
  147. bool quote_prefix() const;
  148. /// <summary>
  149. /// If quote is true, enables a single-quote prefix for all text values in cells
  150. /// using this format (e.g. "abc" will appear as "'abc"). The text will also not
  151. /// be stored in sharedStrings when this is enabled.
  152. /// </summary>
  153. void quote_prefix(bool quote);
  154. /// <summary>
  155. /// Returns true if this format has a corresponding style applied.
  156. /// </summary>
  157. bool has_style() const;
  158. /// <summary>
  159. /// Removes the style from this format if it exists.
  160. /// </summary>
  161. void clear_style();
  162. /// <summary>
  163. /// Sets the style of this format to a style with the given name.
  164. /// </summary>
  165. format style(const std::string &name);
  166. /// <summary>
  167. /// Sets the style of this format to new_style.
  168. /// </summary>
  169. format style(const class style &new_style);
  170. /// <summary>
  171. /// Returns the style of this format. If it has no style, an invalid_parameter
  172. /// exception will be thrown.
  173. /// </summary>
  174. class style style();
  175. /// <summary>
  176. /// Returns the style of this format. If it has no style, an invalid_parameters
  177. /// exception will be thrown.
  178. /// </summary>
  179. const class style style() const;
  180. private:
  181. friend struct detail::stylesheet;
  182. friend class detail::xlsx_producer;
  183. friend class detail::xlsx_consumer;
  184. friend class cell;
  185. /// <summary>
  186. /// Constructs a format from an impl pointer.
  187. /// </summary>
  188. format(detail::format_impl *d);
  189. /// <summary>
  190. /// The internal implementation of this format
  191. /// </summary>
  192. detail::format_impl *d_;
  193. };
  194. } // namespace xlnt