1#ifndef OPENXLSX_XLSTYLES_HPP
2#define OPENXLSX_XLSTYLES_HPP
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
15#include <unordered_map>
19#include "OpenXLSX-Exports.hpp"
26 using namespace std::literals::string_view_literals;
238 uint32_t numberFormatId()
const;
244 std::string formatCode()
const;
251 bool setNumberFormatId(uint32_t newNumberFormatId);
252 bool setFormatCode(std::string_view newFormatCode);
258 std::string summary()
const;
261 std::unique_ptr<XMLNode> m_numberFormatNode;
316 size_t count()
const;
345 uint32_t numberFormatIdFromIndex(
XLStyleIndex index)
const;
352 uint32_t createNumberFormat(std::string_view formatCode);
358 uint32_t getFreeNumberFormatId()
const;
369 std::unique_ptr<XMLNode> m_numberFormatsNode;
370 std::vector<XLNumberFormat> m_numberFormats;
429 std::string fontName()
const;
435 size_t fontCharset()
const;
441 size_t fontFamily()
const;
447 size_t fontSize()
const;
471 bool strikethrough()
const;
495 bool outline()
const;
507 bool condense()
const;
520 XLFont& setFontName(std::string_view newName);
521 XLFont& setFontCharset(
size_t newCharset);
522 XLFont& setFontFamily(
size_t newFamily);
523 XLFont& setFontSize(
size_t newSize);
525 XLFont& setBold(
bool set =
true);
526 XLFont& setItalic(
bool set =
true);
527 XLFont& setStrikethrough(
bool set =
true);
531 XLFont& setOutline(
bool set =
true);
532 XLFont& setShadow(
bool set =
true);
533 XLFont& setCondense(
bool set =
true);
534 XLFont& setExtend(
bool set =
true);
540 std::string summary()
const;
543 std::unique_ptr<XMLNode> m_fontNode;
598 size_t count()
const;
630 XLStyleIndex findOrCreate(XLFont copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
633 std::unique_ptr<XMLNode> m_fontsNode;
634 std::vector<XLFont> m_fonts;
635 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
703 bool automatic()
const;
704 uint32_t indexed()
const;
705 uint32_t theme()
const;
714 bool setTint(
double newTint);
715 bool setAutomatic(
bool set =
true);
716 bool setIndexed(uint32_t newIndex);
717 bool setTheme(uint32_t newTheme);
723 std::string summary()
const;
726 std::unique_ptr<XMLNode> m_colorNode;
785 double position()
const;
793 bool setPosition(
double newPosition);
799 std::string summary()
const;
802 std::unique_ptr<XMLNode> m_stopNode;
857 size_t count()
const;
881 std::string summary()
const;
884 std::unique_ptr<XMLNode> m_gradientNode;
885 std::vector<XLGradientStop> m_gradientStops;
950 bool setFillType(
XLFillType newFillType,
bool force =
false);
958 void throwOnFillType(
XLFillType typeToThrowOn,
const char* functionName)
const;
967 XMLNode getValidFillDescription(
XLFillType fillTypeIfEmpty,
const char* functionName);
998 bool setDegree(
double newDegree);
999 bool setLeft(
double newLeft);
1000 bool setRight(
double newRight);
1001 bool setTop(
double newTop);
1002 bool setBottom(
double newBottom);
1017 std::string summary();
1020 std::unique_ptr<XMLNode> m_fillNode;
1075 size_t count()
const;
1097 XLStyleIndex create(
XLFill copyFrom =
XLFill{}, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
1103 XLStyleIndex findOrCreate(XLFill copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
1106 std::unique_ptr<XMLNode> m_fillsNode;
1107 std::vector<XLFill> m_fills;
1108 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
1171 explicit operator bool()
const;
1186 std::string summary()
const;
1189 std::unique_ptr<XMLNode> m_lineNode;
1246 bool diagonalUp()
const;
1252 bool diagonalDown()
const;
1258 bool outline()
const;
1300 XLLine horizontal()
const;
1308 XLBorder& setDiagonalUp(
bool set =
true);
1309 XLBorder& setDiagonalDown(
bool set =
true);
1310 XLBorder& setOutline(
bool set =
true);
1324 std::string summary()
const;
1327 std::unique_ptr<XMLNode> m_borderNode;
1328 inline static const std::vector<std::string_view> m_nodeOrder =
1329 {
"left",
"right",
"top",
"bottom",
"diagonal",
"vertical",
"horizontal"};
1384 size_t count()
const;
1412 XLStyleIndex findOrCreate(XLBorder copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
1415 std::unique_ptr<XMLNode> m_bordersNode;
1416 std::vector<XLBorder> m_borders;
1417 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
1488 uint16_t textRotation()
const;
1494 bool wrapText()
const;
1500 uint32_t indent()
const;
1507 int32_t relativeIndent()
const;
1513 bool justifyLastLine()
const;
1519 bool shrinkToFit()
const;
1525 uint32_t readingOrder()
const;
1543 bool setTextRotation(uint16_t newRotation);
1544 bool setWrapText(
bool set =
true);
1545 bool setIndent(uint32_t newIndent);
1546 bool setRelativeIndent(int32_t newIndent);
1547 bool setJustifyLastLine(
bool set =
true);
1548 bool setShrinkToFit(
bool set =
true);
1549 bool setReadingOrder(
1550 uint32_t newReadingOrder);
1556 std::string summary()
const;
1559 std::unique_ptr<XMLNode> m_alignmentNode;
1617 uint32_t numberFormatId()
const;
1649 bool applyNumberFormat()
const;
1655 bool applyFont()
const;
1661 bool applyFill()
const;
1667 bool applyBorder()
const;
1673 bool applyAlignment()
const;
1679 bool applyProtection()
const;
1687 bool quotePrefix()
const;
1695 bool pivotButton()
const;
1701 bool locked()
const;
1707 bool hidden()
const;
1714 XLAlignment alignment(
bool createIfMissing =
false)
const;
1750 std::string summary()
const;
1753 std::unique_ptr<XMLNode> m_cellFormatNode;
1754 bool m_permitXfId{
false};
1755 inline static const std::vector<std::string_view> m_nodeOrder = {
"alignment",
"protection"};
1811 size_t count()
const;
1841 XLStyleIndex findOrCreate(XLCellFormat copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
1844 std::unique_ptr<XMLNode> m_cellFormatsNode;
1845 std::vector<XLCellFormat> m_cellFormats;
1846 bool m_permitXfId{
false};
1847 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
1912 std::string name()
const;
1925 uint32_t builtinId()
const;
1932 uint32_t outlineStyle()
const;
1938 bool hidden()
const;
1944 bool customBuiltin()
const;
1956 bool setName(std::string_view newName);
1958 bool setBuiltinId(uint32_t newBuiltinId);
1959 bool setOutlineStyle(uint32_t newOutlineStyle);
1960 bool setHidden(
bool set =
true);
1961 bool setCustomBuiltin(
bool set =
true);
1971 std::string summary()
const;
1974 std::unique_ptr<XMLNode> m_cellStyleNode;
2029 size_t count()
const;
2053 std::unique_ptr<XMLNode> m_cellStylesNode;
2054 std::vector<XLCellStyle> m_cellStyles;
2128 bool hasFont()
const;
2129 bool hasNumFmt()
const;
2130 bool hasFill()
const;
2131 bool hasAlignment()
const;
2132 bool hasBorder()
const;
2140 void clearAlignment();
2157 std::string summary()
const;
2165 std::unique_ptr<XMLDocument> m_xmlDocument;
2226 size_t count()
const;
2247 XLStyleIndex create(
XLDxf copyFrom =
XLDxf{}, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
2250 mutable XMLNode m_dxfsNode;
2251 std::vector<XLDxf> m_dxfs;
2279 explicit XLStyles(gsl::not_null<XLXmlData*> xmlData,
2280 bool suppressWarnings =
false,
2319 uint32_t createNumberFormat(std::string_view formatCode);
2391 std::optional<XLStyleIndex> fontId = std::nullopt,
2392 std::optional<XLStyleIndex> fillId = std::nullopt,
2393 std::optional<XLStyleIndex> borderId = std::nullopt,
2394 std::optional<XLStyleIndex> numFmtId = std::nullopt);
2417 bool m_suppressWarnings;
2418 std::unique_ptr<XLNumberFormats> m_numberFormats;
2419 std::unique_ptr<XLFonts> m_fonts;
2420 std::unique_ptr<XLFills> m_fills;
2421 std::unique_ptr<XLBorders> m_borders;
2422 std::unique_ptr<XLCellFormats> m_cellStyleFormats;
2423 std::unique_ptr<XLCellFormats> m_cellFormats;
2424 std::unique_ptr<XLCellStyles> m_cellStyles;
2425 std::unique_ptr<XLDxfs> m_dxfs;
2430# pragma warning(pop)
Definition XLXmlParser.hpp:84
An encapsulation of an alignment item.
Definition XLStyles.hpp:1426
XLAlignment & operator=(XLAlignment &&other) noexcept=default
Move assignment operator.
XLAlignment(XLAlignment &&other) noexcept=default
Move Constructor.
An encapsulation of a border item.
Definition XLStyles.hpp:1196
XLBorder & operator=(XLBorder &&other) noexcept=default
Move assignment operator.
XLBorder(XLBorder &&other) noexcept=default
Move Constructor.
An encapsulation of the XLSX borders.
Definition XLStyles.hpp:1336
XLBorders & operator=(XLBorders &&other) noexcept=default
Move assignment operator.
XLBorder operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to borderByIndex.
Definition XLStyles.hpp:1398
An encapsulation of a cell style item.
Definition XLStyles.hpp:1856
XLUnsupportedElement extLst() const
Unsupported getter.
Definition XLStyles.hpp:1949
XLCellStyle & operator=(XLCellStyle &&other) noexcept=default
Move assignment operator.
XLCellStyle(XLCellStyle &&other) noexcept=default
Move Constructor.
An encapsulation of the XLSX cell styles.
Definition XLStyles.hpp:1981
XLCellStyles & operator=(XLCellStyles &&other) noexcept=default
Move assignment operator.
XLCellStyle operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to cellStyleByIndex.
Definition XLStyles.hpp:2042
Definition XLColor.hpp:22
An encapsulation of an XLSX Data Bar Color (CT_Color) item.
Definition XLStyles.hpp:644
bool set(XLColor newColor)
Definition XLStyles.hpp:713
XLDataBarColor & operator=(XLDataBarColor &&other) noexcept=default
Move assignment operator.
XLDataBarColor(XLDataBarColor &&other) noexcept=default
Move Constructor.
~XLDataBarColor()=default
An encapsulation of a differential cell format item (DXF)
Definition XLStyles.hpp:2063
XLUnsupportedElement extLst() const
Unsupported getter.
Definition XLStyles.hpp:2146
XMLNode node() const
Access the underlying XML node.
Definition XLStyles.hpp:2162
An encapsulation of the XLSX differential cell formats (dxfs)
Definition XLStyles.hpp:2178
XLDxf operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to dxfByIndex.
Definition XLStyles.hpp:2239
An encapsulation of a fill item.
Definition XLStyles.hpp:892
XLFill(XLFill &&other) noexcept=default
Move Constructor.
XLFill & operator=(XLFill &&other) noexcept=default
Move assignment operator.
An encapsulation of the XLSX fills.
Definition XLStyles.hpp:1027
XLFill operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to fillByIndex.
Definition XLStyles.hpp:1089
XLFills & operator=(XLFills &&other) noexcept=default
Move assignment operator.
An encapsulation of a font item.
Definition XLStyles.hpp:379
XLFont(XLFont &&other) noexcept=default
Move Constructor.
XLFont & operator=(XLFont &&other) noexcept=default
Move assignment operator.
An encapsulation of the XLSX fonts.
Definition XLStyles.hpp:550
XLFonts & operator=(XLFonts &&other) noexcept=default
Move assignment operator.
XLFont operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to fontByIndex.
Definition XLStyles.hpp:612
An encapsulation of an fill::gradientFill::stop item.
Definition XLStyles.hpp:735
XLGradientStop & operator=(XLGradientStop &&other) noexcept=default
Move assignment operator.
~XLGradientStop()=default
XLGradientStop(XLGradientStop &&other) noexcept=default
Move Constructor.
An encapsulation of an array of fill::gradientFill::stop items.
Definition XLStyles.hpp:809
XLGradientStops & operator=(XLGradientStops &&other) noexcept=default
Move assignment operator.
XLGradientStop operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to stopByIndex.
Definition XLStyles.hpp:871
An encapsulation of a line item.
Definition XLStyles.hpp:1117
XLLine(XLLine &&other) noexcept=default
Move Constructor.
XLLine & operator=(XLLine &&other) noexcept=default
Move assignment operator.
An encapsulation of the styles file (xl/styles.xml) in an Excel document package.
Definition XLStyles.hpp:2265
XLDxfs & diffCellFormats() const
Backward compatibility alias for dxfs()
Definition XLStyles.hpp:2372
The XLUnsupportedElement class provides a stub implementation that can be used as function parameter ...
Definition XLXmlFile.hpp:28
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition IZipArchive.hpp:18
XLFillType
Definition XLStyles.hpp:103
@ XLPatternFill
Definition XLStyles.hpp:105
@ XLGradientFill
Definition XLStyles.hpp:104
@ XLFillTypeInvalid
Definition XLStyles.hpp:106
XLAlignmentStyle
Definition XLStyles.hpp:167
@ XLAlignInvalid
Definition XLStyles.hpp:178
@ XLAlignRight
Definition XLStyles.hpp:170
@ XLAlignBottom
Definition XLStyles.hpp:173
@ XLAlignLeft
Definition XLStyles.hpp:169
@ XLAlignCenterContinuous
Definition XLStyles.hpp:176
@ XLAlignGeneral
Definition XLStyles.hpp:168
@ XLAlignJustify
Definition XLStyles.hpp:175
@ XLAlignFill
Definition XLStyles.hpp:174
@ XLAlignDistributed
Definition XLStyles.hpp:177
@ XLAlignCenter
Definition XLStyles.hpp:171
@ XLAlignTop
Definition XLStyles.hpp:172
XLLineType
Definition XLStyles.hpp:138
@ XLLineLeft
Definition XLStyles.hpp:139
@ XLLineBottom
Definition XLStyles.hpp:142
@ XLLineVertical
Definition XLStyles.hpp:144
@ XLLineDiagonal
Definition XLStyles.hpp:143
@ XLLineRight
Definition XLStyles.hpp:140
@ XLLineHorizontal
Definition XLStyles.hpp:145
@ XLLineInvalid
Definition XLStyles.hpp:146
@ XLLineTop
Definition XLStyles.hpp:141
XLPatternType
Definition XLStyles.hpp:111
@ XLPatternNone
Definition XLStyles.hpp:112
@ XLPatternLightDown
Definition XLStyles.hpp:125
@ XLPatternGray0625
Definition XLStyles.hpp:130
@ XLPatternDarkGray
Definition XLStyles.hpp:115
@ XLPatternTypeInvalid
Definition XLStyles.hpp:131
@ XLPatternLightHorizontal
Definition XLStyles.hpp:123
@ XLPatternDarkDown
Definition XLStyles.hpp:119
@ XLPatternDarkHorizontal
Definition XLStyles.hpp:117
@ XLPatternSolid
Definition XLStyles.hpp:113
@ XLPatternDarkUp
Definition XLStyles.hpp:120
@ XLPatternDarkGrid
Definition XLStyles.hpp:121
@ XLPatternGray125
Definition XLStyles.hpp:129
@ XLPatternLightVertical
Definition XLStyles.hpp:124
@ XLPatternLightUp
Definition XLStyles.hpp:126
@ XLPatternDarkTrellis
Definition XLStyles.hpp:122
@ XLPatternDarkVertical
Definition XLStyles.hpp:118
@ XLPatternLightGray
Definition XLStyles.hpp:116
@ XLPatternLightGrid
Definition XLStyles.hpp:127
@ XLPatternLightTrellis
Definition XLStyles.hpp:128
@ XLPatternMediumGray
Definition XLStyles.hpp:114
XLUnderlineStyle
Definition XLStyles.hpp:80
@ XLUnderlineSingleAccounting
Definition XLStyles.hpp:84
@ XLUnderlineDoubleAccounting
Definition XLStyles.hpp:85
@ XLUnderlineSingle
Definition XLStyles.hpp:82
@ XLUnderlineNone
Definition XLStyles.hpp:81
@ XLUnderlineInvalid
Definition XLStyles.hpp:86
@ XLUnderlineDouble
Definition XLStyles.hpp:83
constexpr const char * XLDefaultPatternBgColor
Definition XLStyles.hpp:136
constexpr const uint32_t XLDefaultFontSize
Definition XLStyles.hpp:54
XLGradientType
Definition XLStyles.hpp:109
@ XLGradientLinear
Definition XLStyles.hpp:109
@ XLGradientTypeInvalid
Definition XLStyles.hpp:109
@ XLGradientPath
Definition XLStyles.hpp:109
constexpr const char * XLDefaultLineStyle
Definition XLStyles.hpp:61
constexpr const XLStyleIndex XLDefaultCellFormat
Definition XLStyles.hpp:49
constexpr const uint32_t XLDefaultFontCharset
Definition XLStyles.hpp:59
constexpr const bool XLCreateIfMissing
Definition XLStyles.hpp:41
constexpr const XLFillType XLDefaultFillType
Definition XLStyles.hpp:133
size_t XLStyleIndex
Definition XLStyles.hpp:31
constexpr const char * XLDefaultPatternFgColor
Definition XLStyles.hpp:135
constexpr const char * XLDefaultStyleEntriesPrefix
Definition XLStyles.hpp:47
constexpr const char * XLDefaultFontColor
Definition XLStyles.hpp:55
constexpr const char * XLDefaultFontName
Definition XLStyles.hpp:57
constexpr const bool XLDoNotCreate
Definition XLStyles.hpp:42
constexpr const char * XLDefaultStylesPrefix
Definition XLStyles.hpp:46
constexpr const uint32_t XLInvalidUInt32
Definition XLStyles.hpp:34
XLFontSchemeStyle
Definition XLStyles.hpp:89
@ XLFontSchemeInvalid
Definition XLStyles.hpp:93
@ XLFontSchemeNone
Definition XLStyles.hpp:90
@ XLFontSchemeMinor
Definition XLStyles.hpp:92
@ XLFontSchemeMajor
Definition XLStyles.hpp:91
XLReadingOrder
Definition XLStyles.hpp:181
@ XLReadingOrderLeftToRight
Definition XLStyles.hpp:181
@ XLReadingOrderContextual
Definition XLStyles.hpp:181
@ XLReadingOrderRightToLeft
Definition XLStyles.hpp:181
constexpr const bool XLForceFillType
Definition XLStyles.hpp:44
XLVerticalAlignRunStyle
Definition XLStyles.hpp:96
@ XLSubscript
Definition XLStyles.hpp:98
@ XLBaseline
Definition XLStyles.hpp:97
@ XLVerticalAlignRunInvalid
Definition XLStyles.hpp:100
@ XLSuperscript
Definition XLStyles.hpp:99
XLLineStyle
Definition XLStyles.hpp:149
@ XLLineStyleNone
Definition XLStyles.hpp:150
@ XLLineStyleMediumDashDotDot
Definition XLStyles.hpp:162
@ XLLineStyleDashDot
Definition XLStyles.hpp:159
@ XLLineStyleMediumDashed
Definition XLStyles.hpp:158
@ XLLineStyleDotted
Definition XLStyles.hpp:154
@ XLLineStyleSlantDashDot
Definition XLStyles.hpp:163
@ XLLineStyleDouble
Definition XLStyles.hpp:156
@ XLLineStyleInvalid
Definition XLStyles.hpp:164
@ XLLineStyleThick
Definition XLStyles.hpp:155
@ XLLineStyleThin
Definition XLStyles.hpp:151
@ XLLineStyleMediumDashDot
Definition XLStyles.hpp:160
@ XLLineStyleDashed
Definition XLStyles.hpp:153
@ XLLineStyleDashDotDot
Definition XLStyles.hpp:161
@ XLLineStyleMedium
Definition XLStyles.hpp:152
@ XLLineStyleHair
Definition XLStyles.hpp:157
constexpr const uint32_t XLInvalidUInt16
Definition XLStyles.hpp:33
constexpr const uint32_t XLDeleteProperty
Definition XLStyles.hpp:35
constexpr const XLStyleIndex XLInvalidStyleIndex
Definition XLStyles.hpp:52
constexpr const XLPatternType XLDefaultPatternType
Definition XLStyles.hpp:134
constexpr const uint32_t XLDefaultFontFamily
Definition XLStyles.hpp:58
constexpr const char * XLDefaultFontColorTheme
Definition XLStyles.hpp:56
constexpr const bool XLPermitXfID
Definition XLStyles.hpp:39
A high-level, human-ergonomic structure representing the styling of a cell or range....
Definition XLStyle.hpp:19