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

The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to all classes which are represented by an .xml file in an .xlsx package. More...

#include <XLXmlFile.hpp>

Inheritance diagram for OpenXLSX::XLXmlFile:
OpenXLSX::XLSheetBase< XLChartsheet > OpenXLSX::XLSheetBase< XLWorksheet > OpenXLSX::XLAppProperties OpenXLSX::XLChart OpenXLSX::XLComments OpenXLSX::XLContentTypes OpenXLSX::XLCustomProperties OpenXLSX::XLDrawing OpenXLSX::XLPersons OpenXLSX::XLPivotCacheDefinition OpenXLSX::XLPivotCacheRecords OpenXLSX::XLPivotTable OpenXLSX::XLProperties OpenXLSX::XLRelationships OpenXLSX::XLSharedStrings OpenXLSX::XLSheet OpenXLSX::XLSheetBase< T, typename > OpenXLSX::XLSlicerCache OpenXLSX::XLStyles OpenXLSX::XLTable OpenXLSX::XLThreadedComments OpenXLSX::XLVmlDrawing OpenXLSX::XLWorkbook

Public Member Functions

 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

Protected Member Functions

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

XLXmlData * m_xmlData {nullptr}

Detailed Description

The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to all classes which are represented by an .xml file in an .xlsx package.

Warning
The XLXmlFile class is not intended to be instantiated on it's own, but to provide an interface for derived classes. Also, it should not be used polymorphically. For that reason, the destructor is not declared virtual.

Constructor & Destructor Documentation

◆ XLXmlFile() [1/4]

OpenXLSX::XLXmlFile::XLXmlFile ( )
default

Default constructor.

◆ XLXmlFile() [2/4]

XLXmlFile::XLXmlFile ( XLXmlData * xmlData)
explicit

Constructor. Creates an object based on the xmlData input.

Parameters
xmlDataAn XLXmlData object with the XML data to be represented by the object.

The constructor creates a new object with the parent XLDocument and the file path as input, with an optional input being a std::string with the XML data. If the XML data is provided by a string, any file with the same path in the .zip file will be overwritten upon saving of the document. If no xmlData is provided, the data will be read from the .zip file, using the given path.

◆ XLXmlFile() [3/4]

OpenXLSX::XLXmlFile::XLXmlFile ( const XLXmlFile & other)
default

Copy constructor. Default implementation used.

Parameters
otherThe object to copy.

◆ XLXmlFile() [4/4]

OpenXLSX::XLXmlFile::XLXmlFile ( XLXmlFile && other)
defaultnoexcept

Move constructor. Default implementation used.

Parameters
otherThe object to move.

◆ ~XLXmlFile()

OpenXLSX::XLXmlFile::~XLXmlFile ( )
default

Destructor. Default implementation used.

Member Function Documentation

◆ getXmlPath()

std::string XLXmlFile::getXmlPath ( ) const

Retrieve the path of the XML data in the .xlsx zip archive via m_xmlData->getXmlPath.

Returns
A std::string with the path. Empty string if m_xmlData is nullptr

provide access to the underlying XLXmlData::getXmlPath() function

◆ operator=() [1/2]

XLXmlFile & OpenXLSX::XLXmlFile::operator= ( const XLXmlFile & other)
default

The copy assignment operator. The default implementation has been used.

Parameters
otherThe object to copy.
Returns
A reference to the new object.

◆ operator=() [2/2]

XLXmlFile & OpenXLSX::XLXmlFile::operator= ( XLXmlFile && other)
defaultnoexcept

The move assignment operator. The default implementation has been used.

Parameters
otherThe object to move.
Returns
A reference to the new object.

◆ package() [1/2]

XLPackageServices & XLXmlFile::package ( )
nodiscard

Narrow package-services port (archive, managed XML parts, relationships, content types).

Decouples Drawing / Pivot / similar parts from the full document façade. Valid only while the parent document remains alive.

◆ package() [2/2]

const XLPackageServices & XLXmlFile::package ( ) const
nodiscard

◆ parentDoc() [1/2]

XLDocument & XLXmlFile::parentDoc ( )

This function provides access to the parent XLDocument object.

Returns
A reference to the parent XLDocument object.
Note
Prefer package() when only archive / XML-part / relationship services are needed.

◆ parentDoc() [2/2]

const XLDocument & XLXmlFile::parentDoc ( ) const

This function provides access to the parent XLDocument object.

Returns
A const reference to the parent XLDocument object.
Note
Prefer package() when only archive / XML-part / relationship services are needed.

◆ partFactory() [1/2]

XLPackagePartFactory & XLXmlFile::partFactory ( )
nodiscard

Narrow package-part factory port (chart / drawing / image / slicer / sheet accessories).

Prefer this over parentDoc() for createChart, sheetDrawing, addImage, createSlicer, etc. Valid only while the parent document remains alive.

◆ partFactory() [2/2]

const XLPackagePartFactory & XLXmlFile::partFactory ( ) const
nodiscard

◆ relationshipID()

std::string XLXmlFile::relationshipID ( ) const
protected

This function returns the relationship ID (the ID used in the XLRelationships objects) for the object.

Returns
A std::string with the ID. Not all spreadsheet objects may have a relationship ID. In those cases an empty string is returned.

◆ setXmlData()

void XLXmlFile::setXmlData ( std::string_view xmlData)
protected

Provide the XML data represented by the object.

Parameters
xmlDataA std::string_view with the XML data.

This method sets the XML data with a std::string as input. The underlying XMLDocument reads the data. When envoking the load_string method in PugiXML, the flag 'parse_ws_pcdata' is passed along with the default flags. This will enable parsing of whitespace characters. If not set, Excel cells with only spaces will be returned as empty strings, which is not what we want. The downside is that whitespace characters such as \n and \t in the input xml file may mess up the parsing.

◆ sharedStrings()

const XLSharedStrings & XLXmlFile::sharedStrings ( ) const
nodiscard

Full workbook SST (including getOrCreate / append).

Convenience forwarding to the parent document; prefer over parentDoc().sharedStrings() when constructing cells/rows or writing strings. Use sharedStringTable() for read-only lookups. Valid only while the parent document remains alive.

◆ sharedStringTable()

const XLSharedStringTable & XLXmlFile::sharedStringTable ( ) const
nodiscard

Read-only shared string table (SST) port.

Prefer this when only resolving indices to text (or looking up existing strings). Valid only while the parent document remains alive.

◆ valid()

bool OpenXLSX::XLXmlFile::valid ( ) const
inline

check whether class is linked to a valid XML file

Returns
true if the class should have a link to valid data
false if accessing any other sheet properties / methods could cause a segmentation fault
Note
for example, if an XLSheet is created with a default constructor, XLSheetBase::valid() (derived from XLXmlFile) would return false

◆ xmlData()

std::string XLXmlFile::xmlData ( XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const

Method for getting the XML data represented by the object.

Parameters
savingDeclaration@optional specify an XML saving declaration to use
Returns
A std::string with the XML data.

This method retrieves the underlying XML data as a std::string.

◆ xmlDataPart() [1/2]

const XLXmlData * OpenXLSX::XLXmlFile::xmlDataPart ( ) const
inlinenodiscardnoexcept

Access the underlying XLXmlData pointer.

◆ xmlDataPart() [2/2]

XLXmlData * OpenXLSX::XLXmlFile::xmlDataPart ( )
inlinenodiscardnoexcept

◆ xmlDocument() [1/2]

XMLDocument & XLXmlFile::xmlDocument ( )

This function provides access to the underlying XMLDocument object.

Returns
A reference to the XMLDocument object.

This method returns a pointer to the underlying XMLDocument resource.

◆ xmlDocument() [2/2]

const XMLDocument & XLXmlFile::xmlDocument ( ) const

This function provides access to the underlying XMLDocument object.

Returns
A const reference to the XMLDocument object.

This method returns a pointer to the underlying XMLDocument resource as const.

Field Documentation

◆ m_xmlData

XLXmlData* OpenXLSX::XLXmlFile::m_xmlData {nullptr}
protected

The underlying XML data object.


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