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

An implementation class encapsulating the properties and behaviours of a spreadsheet cell. More...

#include <XLCell.hpp>

Inheritance diagram for OpenXLSX::XLCell:
OpenXLSX::XLCellAssignable

Public Member Functions

 XLCell ()
 Default constructor. Constructs a null object.
 
 XLCell (const XMLNode &cellNode, const XLSharedStrings &sharedStrings, XLWorksheet *wks=nullptr)
 Constructs an XLCell mapped to an XML node.
 
 XLCell (const XLCell &other)
 Copy constructor.
 
 XLCell (XLCell &&other) noexcept
 Move constructor.
 
virtual ~XLCell ()
 Destructor.
 
virtual XLCelloperator= (const XLCell &other)
 Copy assignment operator.
 
virtual XLCelloperator= (XLCell &&other) noexcept
 Move assignment operator.
 
void copyFrom (XLCell const &other)
 Copy contents of a cell, value & formula.
 
bool empty () const
 test if cell object has no (valid) content
 
 operator bool () const
 opposite of empty()
 
void clear (uint32_t keep)
 clear all cell content and attributes except for the cell reference (attribute r)
 
XLCellValueProxyvalue ()
 Retrieves the mutable value proxy for the cell.
 
const XLCellValueProxyvalue () const
 Retrieves the read-only value proxy for the cell.
 
XLCellReference cellReference () const
 get the XLCellReference object for the cell.
 
XLCell offset (uint16_t rowOffset, uint16_t colOffset) const
 get the XLCell object from the current cell offset
 
bool hasFormula () const
 test if cell has a formula (XML) node, even if it is an empty string
 
XLFormulaProxyformula ()
 Retrieves the mutable formula proxy for the cell.
 
const XLFormulaProxyformula () const
 Retrieves the read-only formula proxy for the cell.
 
std::string getString () const
 
XLStyleIndex cellFormat () const
 Get the array index of xl/styles.xml:<styleSheet>:<cellXfs> for the style used in this cell. This value is stored in the s attribute of a cell like so: s="2".
 
XLCellsetCellFormat (XLStyleIndex cellFormatIndex)
 Set the cell style (attribute s) with a reference to the array index of xl/styles.xml:<styleSheet>:<cellXfs>
 
XLCellsetStyle (const XLStyle &style)
 Apply a high-level XLStyle to this cell. Automatically creates or reuses the required underlying XML structures in xl/styles.xml.
 
XLThreadedComment addComment (std::string_view text, std::string_view author="")
 Add a modern threaded comment (Excel 365) to this cell fluently.
 
XLCelladdNote (std::string_view text, std::string_view author="")
 Add a legacy yellow note to this cell fluently.
 
void print (std::basic_ostream< char > &ostr) const
 Print the XML contents of the XLCell using the underlying XMLNode print function.
 

Friends

class XLCellIterator
 
class XLCellValueProxy
 
class XLFormulaProxy
 
class XLRowDataIterator
 
bool operator== (const XLCell &lhs, const XLCell &rhs)
 
bool operator!= (const XLCell &lhs, const XLCell &rhs)
 

Detailed Description

An implementation class encapsulating the properties and behaviours of a spreadsheet cell.

Constructor & Destructor Documentation

◆ XLCell() [1/4]

XLCell::XLCell ( )

Default constructor. Constructs a null object.

◆ XLCell() [2/4]

XLCell::XLCell ( const XMLNode cellNode,
const XLSharedStrings sharedStrings,
XLWorksheet wks = nullptr 
)

Constructs an XLCell mapped to an XML node.

Parameters
cellNodeThe underlying XML node representing the cell.
sharedStringsReference to the workbook's shared strings table.
wksPointer to the parent worksheet for fluent API support.

This constructor creates a XLCell object based on the cell XMLNode input parameter, and is intended for use when the corresponding cell XMLNode already exist. If a cell XMLNode does not exist (i.e., the cell is empty), use the relevant constructor to create an XLCell from a XLCellReference parameter.

◆ XLCell() [3/4]

XLCell::XLCell ( const XLCell other)

Copy constructor.

Parameters
otherThe XLCell object to be copied.
Note
The copy constructor has been deleted, as it makes no sense to copy a cell. If the objective is to copy the getValue, create the the target object and then use the copy assignment operator.

◆ XLCell() [4/4]

XLCell::XLCell ( XLCell &&  other)
noexcept

Move constructor.

Parameters
otherThe XLCell object to be moved
Note
The move constructor has been deleted, as it makes no sense to move a cell.

◆ ~XLCell()

XLCell::~XLCell ( )
virtualdefault

Destructor.

Note
Using the default destructor

Member Function Documentation

◆ addComment()

XLThreadedComment XLCell::addComment ( std::string_view  text,
std::string_view  author = "" 
)

Add a modern threaded comment (Excel 365) to this cell fluently.

◆ addNote()

XLCell & XLCell::addNote ( std::string_view  text,
std::string_view  author = "" 
)

Add a legacy yellow note to this cell fluently.

Applies a high-level XLStyle object by resolving it into the underlying OpenXLSX XLStyles system.

◆ cellFormat()

size_t XLCell::cellFormat ( ) const

Get the array index of xl/styles.xml:<styleSheet>:<cellXfs> for the style used in this cell. This value is stored in the s attribute of a cell like so: s="2".

Returns
The index of the applicable format style

◆ cellReference()

XLCellReference XLCell::cellReference ( ) const

get the XLCellReference object for the cell.

Returns
A reference to the cells' XLCellReference object.

◆ clear()

void XLCell::clear ( uint32_t  keep)

clear all cell content and attributes except for the cell reference (attribute r)

Parameters
keepdo not clear cell properties whose flags are set in keep (XLKeepCellStyle, XLKeepCellType, XLKeepCellValue, XLKeepCellFormula), flags can be combined with bitwise OR
Note
due to the way OOXML separates comments from the cells, this function will not clear a cell comment - refer to XLComments& XLSheet::comments() for that

◆ copyFrom()

void XLCell::copyFrom ( XLCell const &  other)

Copy contents of a cell, value & formula.

Parameters
otherThe XLCell object from which to copy

◆ empty()

bool XLCell::empty ( ) const

test if cell object has no (valid) content

Returns

◆ formula() [1/2]

XLFormulaProxy & XLCell::formula ( )

Retrieves the mutable formula proxy for the cell.

Returns
Reference to the XLFormulaProxy.

◆ formula() [2/2]

const XLFormulaProxy & XLCell::formula ( ) const

Retrieves the read-only formula proxy for the cell.

Returns
Const reference to the XLFormulaProxy.

◆ getString()

std::string OpenXLSX::XLCell::getString ( ) const
inline

◆ hasFormula()

bool XLCell::hasFormula ( ) const

test if cell has a formula (XML) node, even if it is an empty string

Returns
true if XML has a formula node, empty or not - otherwise false

◆ offset()

XLCell XLCell::offset ( uint16_t  rowOffset,
uint16_t  colOffset 
) const

get the XLCell object from the current cell offset

Returns
A reference to the XLCell object.

◆ operator bool()

XLCell::operator bool ( ) const
explicit

opposite of empty()

Returns

◆ operator=() [1/2]

XLCell & XLCell::operator= ( const XLCell other)
virtual

Copy assignment operator.

Parameters
otherThe XLCell object to be copy assigned
Returns
A reference to the new object
Note
Copies only the cell contents, not the pointer to parent worksheet etc.

Reimplemented in OpenXLSX::XLCellAssignable.

◆ operator=() [2/2]

XLCell & XLCell::operator= ( XLCell &&  other)
virtualnoexcept

Move assignment operator.

Parameters
otherThe XLCell object to be move assigned
Returns
A reference to the new object
Note
The move assignment constructor has been deleted, as it makes no sense to move a cell.

Reimplemented in OpenXLSX::XLCellAssignable.

◆ print()

void XLCell::print ( std::basic_ostream< char > &  ostr) const

Print the XML contents of the XLCell using the underlying XMLNode print function.

◆ setCellFormat()

XLCell & XLCell::setCellFormat ( XLStyleIndex  cellFormatIndex)

Set the cell style (attribute s) with a reference to the array index of xl/styles.xml:<styleSheet>:<cellXfs>

Parameters
cellFormatIndexThe style to set, corresponding to the nidex of XLStyles::cellStyles()
Returns
True on success, false on failure

set the s attribute of the cell node, pointing to an xl/styles.xml cellXfs index the attribute will be created if not existant, function will fail if attribute creation fails

◆ setStyle()

XLCell & XLCell::setStyle ( const XLStyle style)

Apply a high-level XLStyle to this cell. Automatically creates or reuses the required underlying XML structures in xl/styles.xml.

Parameters
styleThe requested high-level style

◆ value() [1/2]

XLCellValueProxy & XLCell::value ( )

Retrieves the mutable value proxy for the cell.

Returns
Reference to the XLCellValueProxy.

◆ value() [2/2]

const XLCellValueProxy & XLCell::value ( ) const

Retrieves the read-only value proxy for the cell.

Returns
Const reference to the XLCellValueProxy.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const XLCell lhs,
const XLCell rhs 
)
friend
Parameters
lhs
rhs
Returns

◆ operator==

bool operator== ( const XLCell lhs,
const XLCell rhs 
)
friend
Parameters
lhs
rhs
Returns

◆ XLCellIterator

friend class XLCellIterator
friend

◆ XLCellValueProxy

friend class XLCellValueProxy
friend

◆ XLFormulaProxy

friend class XLFormulaProxy
friend

◆ XLRowDataIterator

friend class XLRowDataIterator
friend

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