OpenXLSX 1.9.1
Loading...
Searching...
No Matches
OpenXLSX::XLCellRange Class Reference

Represents a rectangular area of cells within a worksheet. More...

#include <XLCellRange.hpp>

Public Member Functions

 XLCellRange ()
 Constructs an uninitialized range.
 
 XLCellRange (const XMLNode &dataNode, const XLCellReference &topLeft, const XLCellReference &bottomRight, const XLSharedStrings &sharedStrings)
 
 ~XLCellRange ()=default
 
 XLCellRange (const XLCellRange &other)=default
 
 XLCellRange (XLCellRange &&other) noexcept=default
 
XLCellRangeoperator= (const XLCellRange &other)=default
 
XLCellRangeoperator= (XLCellRange &&other) noexcept=default
 
void fetchColumnStyles ()
 Scans the worksheet for column-level styles and caches them.
 
XLCellReference topLeft () const
 
XLCellReference bottomRight () const
 
std::string address () const
 
uint32_t numRows () const
 
uint16_t numColumns () const
 
XLCellIterator begin () const
 
XLCellIterator end () const
 
void applyStyle (const XLStyle &style)
 Apply a high-level style to all cells within this range.
 
void setBorderOutline (XLLineStyle style, XLColor color)
 Set border style specifically for the outer edges of this range.
 
template<typename T >
std::vector< std::vector< T > > getValue () const
 Read the range into a 2D matrix of type T.
 
template<typename T >
void setValue (const std::vector< std::vector< T > > &matrix)
 
bool empty () const
 Returns true if the range is uninitialized or points to an invalid worksheet node.
 
void clear ()
 Clears the values of all cells within the range.
 
template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLDateTime>>>
XLCellRangeoperator= (T value)
 Assigns a single value to every cell in the range.
 
XLCellRangesetFormat (XLStyleIndex cellFormatIndex)
 Applies a cell format (style) to all cells in the range.
 
XLCellRange intersect (const XLCellRange &other) const
 Calculates the intersection area between this range and another.
 

Friends

class XLCellIterator
 

Detailed Description

Represents a rectangular area of cells within a worksheet.

This class provides a high-level interface for bulk operations on cells, such as clearing values, setting formats, or iterating over a subset of the worksheet. It maintains a cache of column styles to ensure efficient cell creation during iteration.

Constructor & Destructor Documentation

◆ XLCellRange() [1/4]

XLCellRange::XLCellRange ( )

Constructs an uninitialized range.

◆ XLCellRange() [2/4]

XLCellRange::XLCellRange ( const XMLNode dataNode,
const XLCellReference topLeft,
const XLCellReference bottomRight,
const XLSharedStrings sharedStrings 
)
explicit
Parameters
dataNodeThe XML node containing sheet data.
topLeftTop-left boundary of the range.
bottomRightBottom-right boundary of the range.
sharedStringsReference to the workbook's shared strings table.
Exceptions
XLInputErrorif topLeft is not truly to the top-left of bottomRight.

Validates that the boundaries form a logical rectangle.

◆ ~XLCellRange()

OpenXLSX::XLCellRange::~XLCellRange ( )
default

◆ XLCellRange() [3/4]

OpenXLSX::XLCellRange::XLCellRange ( const XLCellRange other)
default

◆ XLCellRange() [4/4]

OpenXLSX::XLCellRange::XLCellRange ( XLCellRange &&  other)
defaultnoexcept

Member Function Documentation

◆ address()

std::string XLCellRange::address ( ) const
Returns
The range reference string (e.g., "A1:C3"), or an empty string if uninitialized.

◆ applyStyle()

void XLCellRange::applyStyle ( const XLStyle style)

Apply a high-level style to all cells within this range.

Parameters
styleThe requested high-level style object.

◆ begin()

XLCellIterator XLCellRange::begin ( ) const

◆ bottomRight()

XLCellReference XLCellRange::bottomRight ( ) const

◆ clear()

void XLCellRange::clear ( )

Clears the values of all cells within the range.

◆ empty()

bool XLCellRange::empty ( ) const

Returns true if the range is uninitialized or points to an invalid worksheet node.

◆ end()

XLCellIterator XLCellRange::end ( ) const

◆ fetchColumnStyles()

void XLCellRange::fetchColumnStyles ( )

Scans the worksheet for column-level styles and caches them.

This is called automatically during construction to ensure XLCellIterator can apply default styles to newly created cells without repeated XML lookups.

Column styles are cached to ensure XLCellIterator can initialize new cells with the correct worksheet-level formatting without re-traversing the XML tree.

◆ getValue()

template<typename T >
std::vector< std::vector< T > > OpenXLSX::XLCellRange::getValue ( ) const

Read the range into a 2D matrix of type T.

◆ intersect()

XLCellRange XLCellRange::intersect ( const XLCellRange other) const

Calculates the intersection area between this range and another.

Returns
A new range representing the common area, or an empty range if they don't overlap.

Performs a coordinate-based intersection. If ranges are on different sheets, the intersection is always empty.

◆ numColumns()

uint16_t XLCellRange::numColumns ( ) const

◆ numRows()

uint32_t XLCellRange::numRows ( ) const

◆ operator=() [1/3]

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

◆ operator=() [2/3]

template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLDateTime>>>
XLCellRange & OpenXLSX::XLCellRange::operator= ( value)
inline

Assigns a single value to every cell in the range.

◆ operator=() [3/3]

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

◆ setBorderOutline()

void XLCellRange::setBorderOutline ( XLLineStyle  style,
XLColor  color 
)

Set border style specifically for the outer edges of this range.

Parameters
styleThe line style (e.g. XLLineStyleThick)
colorThe line color (e.g. XLColor("000000"))

◆ setFormat()

XLCellRange & XLCellRange::setFormat ( XLStyleIndex  cellFormatIndex)

Applies a cell format (style) to all cells in the range.

Parameters
cellFormatIndexThe index in the workbook's style sheet.
Returns
true on success.

◆ setValue()

template<typename T >
void OpenXLSX::XLCellRange::setValue ( const std::vector< std::vector< T > > &  matrix)

◆ topLeft()

XLCellReference XLCellRange::topLeft ( ) const

Friends And Related Symbol Documentation

◆ XLCellIterator

friend class XLCellIterator
friend

The documentation for this class was generated from the following files: