OpenXLSX 1.9.1
Loading...
Searching...
No Matches
XLUtilities.hpp File Reference
#include <fstream>
#include <pugixml.hpp>
#include <string>
#include <string_view>
#include <vector>
#include "XLCellReference.hpp"
#include "XLCellValue.hpp"
#include "XLConstants.hpp"
#include "XLContentTypes.hpp"
#include "XLRelationships.hpp"
#include "XLStyles.hpp"
#include "XLXmlParser.hpp"

Go to the source code of this file.

Namespaces

namespace  OpenXLSX
 

Functions

bool OpenXLSX::isCleanXmlString (std::string_view sv) noexcept
 Checks if a string contains only valid XML 1.0 characters.
 
std::string OpenXLSX::sanitizeXmlString (std::string_view sv)
 Removes invalid XML 1.0 control characters from a string to prevent file corruption.
 
uint16_t OpenXLSX::extractColumnFromCellRef (const char *cellRef) noexcept
 Lightweight function to extract column number from a cell reference string. This is a performance-optimized alternative to creating XLCellReference objects.
 
char * OpenXLSX::columnToLetters (uint16_t colNo, char *buffer) noexcept
 Convert column number to column letter string (A, B, ..., Z, AA, AB, ..., XFD) Performance optimization: avoids creating full XLCellReference object.
 
char * OpenXLSX::makeCellAddress (uint32_t row, uint16_t col, char *buffer) noexcept
 Generate cell address string directly without creating XLCellReference object. Performance optimization: for use in hot loops where address generation is frequent.
 
template<class T >
void OpenXLSX::ignore (const T &)
 Get rid of compiler warnings about unused variables (-Wunused-variable) or unused parameters (-Wunusued-parameter)
 
std::string OpenXLSX::XLValueTypeString (XLValueType t)
 Get a string representation of pugi::xml_node_type.
 
std::string OpenXLSX::xml_node_type_string (pugi::xml_node_type t)
 Get a string representation of pugi::xml_node_type.
 
std::string OpenXLSX::XLContentTypeString (OpenXLSX::XLContentType const &t)
 Get a string representation of OpenXLSX::XLContentType.
 
std::string OpenXLSX::XLRelationshipTypeString (OpenXLSX::XLRelationshipType const &t)
 Get a string representation of OpenXLSX::XLRelationshipType.
 
XMLNode OpenXLSX::getRowNode (XMLNode sheetDataNode, uint32_t rowNumber, uint32_t *hintRowNumber=nullptr, XMLNode *hintRowNode=nullptr)
 
std::vector< XLStyleIndexOpenXLSX::getColumnStyles (XMLNode rowNode, uint16_t count)
 get the style attribute s for the indicated column, if any is set
 
XLStyleIndex OpenXLSX::getColumnStyle (XMLNode rowNode, uint16_t colNo)
 
void OpenXLSX::setDefaultCellAttributes (XMLNode cellNode, const std::string &cellRef, XMLNode rowNode, uint16_t colNo, std::vector< XLStyleIndex > const &colStyles={})
 set the cell reference, and a default cell style attribute if and only if row or column style is != XLDefaultCellFormat
 
void OpenXLSX::setDefaultCellAttributes (XMLNode cellNode, const char *cellRef, XMLNode rowNode, uint16_t colNo, std::vector< XLStyleIndex > const &colStyles={})
 Overload accepting const char* for cell reference - avoids std::string allocation Performance optimization: for use in hot loops where address generation is frequent.
 
XMLNode OpenXLSX::getCellNode (XMLNode rowNode, uint16_t columnNumber, uint32_t rowNumber=0, std::vector< XLStyleIndex > const &colStyles={}, uint16_t *hintColNumber=nullptr, XMLNode *hintCellNode=nullptr)
 Retrieve the xml node representing the cell at the given row and column. If the node doesn't exist, it will be created.
 
int OpenXLSX::findStringInVector (std::string const &nodeName, std::vector< std::string_view > const &nodeOrder)
 
void OpenXLSX::copyLeadingWhitespaces (XMLNode &parent, XMLNode fromNode, XMLNode toNode)
 copy all leading pc_data nodes from fromNode to toNode
 
XMLNode OpenXLSX::appendAndGetNode (XMLNode &parent, std::string const &nodeName, std::vector< std::string_view > const &nodeOrder={}, bool force_ns=false)
 ensure that node with nodeName exists in parent and return it
 
XMLAttribute OpenXLSX::appendAndGetAttribute (XMLNode &node, std::string const &attrName, std::string const &attrDefaultVal)
 
XMLAttribute OpenXLSX::appendAndSetAttribute (XMLNode &node, std::string const &attrName, std::string const &attrVal)
 
XMLAttribute OpenXLSX::appendAndGetNodeAttribute (XMLNode &parent, std::string const &nodeName, std::string const &attrName, std::string const &attrDefaultVal, std::vector< std::string_view > const &nodeOrder={})
 ensure that node with nodeName exists in parent, has an attribute with attrName and return that attribute
 
XMLAttribute OpenXLSX::appendAndSetNodeAttribute (XMLNode &parent, std::string const &nodeName, std::string const &attrName, std::string const &attrVal, bool removeAttributes=XLKeepAttributes, std::vector< std::string_view > const &nodeOrder={})
 ensure that node with nodeName exists in parent, has an attribute with attrName, set attribute value and return that attribute
 
bool OpenXLSX::getBoolAttributeWhenOmittedMeansTrue (XMLNode &parent, std::string const &tagName, std::string const &attrName="val")
 special bool attribute getter function for tags that should have a val="true" or val="false" attribute, but when omitted shall default to "true"
 
std::pair< uint32_t, uint32_t > OpenXLSX::getImageDimensions (const std::string &data)
 Extract image dimensions (width and height) from raw image data (PNG/JPEG)
 

Variables

constexpr const bool OpenXLSX::XLRemoveAttributes = true
 
constexpr const bool OpenXLSX::XLKeepAttributes = false
 
constexpr const int OpenXLSX::SORT_INDEX_NOT_FOUND = -1
 find the index of nodeName in nodeOrder