OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
OpenXLSX::XLStyles Class Reference

An encapsulation of the styles file (xl/styles.xml) in an Excel document package. More...

#include <XLStyles.hpp>

Inheritance diagram for OpenXLSX::XLStyles:
OpenXLSX::XLXmlFile

Data Structures

struct  StyleCacheImpl

Public Member Functions

 XLStyles ()
 XLStyles (gsl::not_null< XLXmlData * > xmlData, bool suppressWarnings=false, std::string_view stylesPrefix=XLDefaultStylesPrefix)
 ~XLStyles ()
 Destructor.
 XLStyles (XLStyles &&other) noexcept
 The move constructor.
 XLStyles (const XLStyles &other)
 The copy constructor.
XLStyles & operator= (XLStyles &&other) noexcept
 move assignment
XLStyles & operator= (const XLStyles &other)
 copy assignment
uint32_t createNumberFormat (std::string_view formatCode)
 Create a new custom number format with a unique ID and format code.
XLNumberFormats & numberFormats () const
 Get the number formats object.
XLFonts & fonts () const
 Get the fonts object.
XLFills & fills () const
 Get the fills object.
XLBorders & borders () const
 Get the borders object.
XLCellFormats & cellStyleFormats () const
 Get the cell style formats object.
XLCellFormats & cellFormats () const
 Get the cell formats object.
XLCellStyles & cellStyles () const
 Get the cell styles object.
XLDxfs & dxfs () const
 Get the differential cell formats object (dxfs).
XLDxfs & diffCellFormats () const
 Backward compatibility alias for dxfs().
XLStyleIndex addDxf (const XLDxf &dxf)
 Add a differential cell format (DXF) to the styles and return its index.
XLStyleIndex addNamedStyle (std::string_view name, std::optional< XLStyleIndex > fontId=std::nullopt, std::optional< XLStyleIndex > fillId=std::nullopt, std::optional< XLStyleIndex > borderId=std::nullopt, std::optional< XLStyleIndex > numFmtId=std::nullopt)
 Add a named style with the given properties and return the index to be used in cells.
XLStyleIndex namedStyle (std::string_view name) const
 Look up a named style by name and return its index for cell formatting.
XLStyleIndex findOrCreateStyle (const XLStyle &style)
 Apply an XLStyle descriptor, deduplicating every sub-pool entry (font, fill, border, numFmt, cellXf) and returning the cellXfs index.
void compactStyles ()
 Compact and deduplicate all styles in the stylesheet.
Public Member Functions inherited from OpenXLSX::XLXmlFile
 XLXmlFile ()=default
 Default constructor.
std::string xmlData (XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
 Method for getting the XML data represented by the object.
 XLXmlFile (XLXmlData *xmlData)
 Constructor. Creates an object based on the xmlData input.
 XLXmlFile (const XLXmlFile &other)=default
 Copy constructor. Default implementation used.
 XLXmlFile (XLXmlFile &&other) noexcept=default
 Move constructor. Default implementation used.
 ~XLXmlFile ()=default
 Destructor. Default implementation used.
bool valid () const
 check whether class is linked to a valid XML file
XLXmlFile & operator= (const XLXmlFile &other)=default
 The copy assignment operator. The default implementation has been used.
XLXmlFile & operator= (XLXmlFile &&other) noexcept=default
 The move assignment operator. The default implementation has been used.
XLDocument & parentDoc ()
 This function provides access to the parent XLDocument object.
const XLDocument & parentDoc () const
 This function provides access to the parent XLDocument object.
XLPackageServices & package ()
 Narrow package-services port (archive, managed XML parts, relationships, content types).
const XLPackageServices & package () const
XLPackagePartFactory & partFactory ()
 Narrow package-part factory port (chart / drawing / image / slicer / sheet accessories).
const XLPackagePartFactory & partFactory () const
const XLSharedStringTable & sharedStringTable () const
 Read-only shared string table (SST) port.
const XLSharedStrings & sharedStrings () const
 Full workbook SST (including getOrCreate / append).
XMLDocument & xmlDocument ()
 This function provides access to the underlying XMLDocument object.
const XMLDocument & xmlDocument () const
 This function provides access to the underlying XMLDocument object.
std::string getXmlPath () const
 Retrieve the path of the XML data in the .xlsx zip archive via m_xmlData->getXmlPath.
const XLXmlData * xmlDataPart () const noexcept
 Access the underlying XLXmlData pointer.
XLXmlData * xmlDataPart () noexcept

Additional Inherited Members

Protected Member Functions inherited from OpenXLSX::XLXmlFile
void setXmlData (std::string_view xmlData)
 Provide the XML data represented by the object.
std::string relationshipID () const
 This function returns the relationship ID (the ID used in the XLRelationships objects) for the object.
Protected Attributes inherited from OpenXLSX::XLXmlFile
XLXmlData * m_xmlData {nullptr}

Detailed Description

An encapsulation of the styles file (xl/styles.xml) in an Excel document package.

Constructor & Destructor Documentation

◆ XLStyles() [1/4]

XLStyles::XLStyles ( )

◆ XLStyles() [2/4]

XLStyles::XLStyles ( gsl::not_null< XLXmlData * > xmlData,
bool suppressWarnings = false,
std::string_view stylesPrefix = XLDefaultStylesPrefix )
explicit
Parameters
xmlData
suppressWarningsif true (SUPRESS_WARNINGS), messages such as "XLStyles: Ignoring currently unsupported <dxfs> node" will be silenced
stylesPrefixPrefix any newly created root style nodes with this text as pugi::node_pcdata

◆ ~XLStyles()

XLStyles::~XLStyles ( )
default

Destructor.

◆ XLStyles() [3/4]

XLStyles::XLStyles ( XLStyles && other)
noexcept

The move constructor.

Parameters
otheran existing styles object other will be assigned to this

◆ XLStyles() [4/4]

XLStyles::XLStyles ( const XLStyles & other)

The copy constructor.

Parameters
otheran existing styles object other will be also referred by this

Member Function Documentation

◆ addDxf()

XLStyleIndex XLStyles::addDxf ( const XLDxf & dxf)

Add a differential cell format (DXF) to the styles and return its index.

Parameters
dxfThe XLDxf object to add.
Returns
The index of the added DXF.

◆ addNamedStyle()

XLStyleIndex XLStyles::addNamedStyle ( std::string_view name,
std::optional< XLStyleIndex > fontId = std::nullopt,
std::optional< XLStyleIndex > fillId = std::nullopt,
std::optional< XLStyleIndex > borderId = std::nullopt,
std::optional< XLStyleIndex > numFmtId = std::nullopt )

Add a named style with the given properties and return the index to be used in cells.

Parameters
nameName of the new style
fontIdOptional font index
fillIdOptional fill index
borderIdOptional border index
numFmtIdOptional number format index
Returns
The XLStyleIndex in cellXfs that corresponds to this named style.

◆ borders()

XLBorders & XLStyles::borders ( ) const

Get the borders object.

Returns
An XLBorders object

◆ cellFormats()

XLCellFormats & XLStyles::cellFormats ( ) const

Get the cell formats object.

Returns
An XLCellFormats object

◆ cellStyleFormats()

XLCellFormats & XLStyles::cellStyleFormats ( ) const

Get the cell style formats object.

Returns
An XLCellFormats object

◆ cellStyles()

XLCellStyles & XLStyles::cellStyles ( ) const

Get the cell styles object.

Returns
An XLCellStyles object

◆ compactStyles()

void XLStyles::compactStyles ( )

Compact and deduplicate all styles in the stylesheet.

Merges identical cellXfs, cleans up unreferenced fonts, fills, and borders while strictly preserving ECMA-376 invariants (fills 0/1, font 0, border 0, cellXf 0).

◆ createNumberFormat()

uint32_t XLStyles::createNumberFormat ( std::string_view formatCode)

Create a new custom number format with a unique ID and format code.

Parameters
formatCodeThe explicit format code string
Returns
The unique number format ID (numFmtId)

◆ diffCellFormats()

XLDxfs & OpenXLSX::XLStyles::diffCellFormats ( ) const
inline

Backward compatibility alias for dxfs().

◆ dxfs()

XLDxfs & XLStyles::dxfs ( ) const

Get the differential cell formats object (dxfs).

Returns
An XLDxfs object

◆ fills()

XLFills & XLStyles::fills ( ) const

Get the fills object.

Returns
An XLFills object

◆ findOrCreateStyle()

XLStyleIndex XLStyles::findOrCreateStyle ( const XLStyle & style)

Apply an XLStyle descriptor, deduplicating every sub-pool entry (font, fill, border, numFmt, cellXf) and returning the cellXfs index.

This is the primary high-level entry point for bulk formatting: call it once per distinct visual style; pass the returned index to every cell that should share that style. Repeated calls with an identical descriptor return the same index in O(1) time.

Parameters
styleA fully populated XLStyle descriptor.
Returns
The XLStyleIndex (in cellXfs) suitable for the cell's 's' attribute.

◆ fonts()

XLFonts & XLStyles::fonts ( ) const

Get the fonts object.

Returns
An XLFonts object

◆ namedStyle()

XLStyleIndex XLStyles::namedStyle ( std::string_view name) const

Look up a named style by name and return its index for cell formatting.

Parameters
nameName of the style
Returns
The XLStyleIndex in cellXfs, or XLInvalidStyleIndex if not found.

◆ numberFormats()

XLNumberFormats & XLStyles::numberFormats ( ) const

Get the number formats object.

Returns
An XLNumberFormats object

◆ operator=() [1/2]

XLStyles & XLStyles::operator= ( const XLStyles & other)

copy assignment

Parameters
other
Returns

◆ operator=() [2/2]

XLStyles & XLStyles::operator= ( XLStyles && other)
noexcept

move assignment

Parameters
other
Returns

The documentation for this class was generated from the following files:
  • /home/runner/work/OpenXLSX-NX/OpenXLSX-NX/OpenXLSX/headers/XLStyles.hpp
  • /home/runner/work/OpenXLSX-NX/OpenXLSX-NX/OpenXLSX/sources/XLStyles.cpp