OpenXLSX 1.9.1
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

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.
 
XLStylesoperator= (XLStyles &&other) noexcept
 move assignment
 
XLStylesoperator= (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.
 
XLNumberFormatsnumberFormats () const
 Get the number formats object.
 
XLFontsfonts () const
 Get the fonts object.
 
XLFillsfills () const
 Get the fills object.
 
XLBordersborders () const
 Get the borders object.
 
XLCellFormatscellStyleFormats () const
 Get the cell style formats object.
 
XLCellFormatscellFormats () const
 Get the cell formats object.
 
XLCellStylescellStyles () const
 Get the cell styles object.
 
XLDxfsdxfs () const
 Get the differential cell formats object (dxfs)
 
XLDxfsdiffCellFormats () 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.
 
- 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
 
XLXmlFileoperator= (const XLXmlFile &other)=default
 The copy assignment operator. The default implementation has been used.
 
XLXmlFileoperator= (XLXmlFile &&other) noexcept=default
 The move assignment operator. The default implementation has been used.
 
XLDocumentparentDoc ()
 This function provides access to the parent XLDocument object.
 
const XLDocumentparentDoc () const
 This function provides access to the parent XLDocument object.
 
XMLDocumentxmlDocument ()
 This function provides access to the underlying XMLDocument object.
 
const XMLDocumentxmlDocument () 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.
 

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
XLXmlDatam_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 ( )

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

◆ 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: