xlnt
Public Member Functions | Static Public Member Functions | List of all members
xlnt::cell_reference Class Reference

An object used to refer to a cell. References have two parts, the column and the row. In Excel, the reference string A1 refers to the top-left-most cell. A cell_reference can be initialized from a string of this form or a 1-indexed ordered pair of the form column, row. More...

#include <cell_reference.hpp>

Public Member Functions

 cell_reference ()
 Default constructor makes a reference to the top-left-most cell, "A1". More...
 
 cell_reference (const char *reference_string)
 Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14). More...
 
 cell_reference (const std::string &reference_string)
 Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14). More...
 
 cell_reference (column_t column, row_t row)
 Constructs a cell_reference from a 1-indexed column index and row index. More...
 
cell_referencemake_absolute (bool absolute_column=true, bool absolute_row=true)
 Converts a coordinate to an absolute coordinate string (e.g. B12 -> $B$12) Defaulting to true, absolute_column and absolute_row can optionally control whether the resulting cell_reference has an absolute column (e.g. B12 -> $B12) and absolute row (e.g. B12 -> B$12) respectively. More...
 
bool column_absolute () const
 Returns true if the reference refers to an absolute column, otherwise false. More...
 
void column_absolute (bool absolute_column)
 Makes this reference have an absolute column if absolute_column is true, otherwise not absolute. More...
 
bool row_absolute () const
 Returns true if the reference refers to an absolute row, otherwise false. More...
 
void row_absolute (bool absolute_row)
 Makes this reference have an absolute row if absolute_row is true, otherwise not absolute. More...
 
column_t column () const
 Returns a string that identifies the column of this reference (e.g. second column from left is "B") More...
 
void column (const std::string &column_string)
 Sets the column of this reference from a string that identifies a particular column. More...
 
column_t::index_t column_index () const
 Returns a 1-indexed numeric index of the column of this reference. More...
 
void column_index (column_t column)
 Sets the column of this reference from a 1-indexed number that identifies a particular column. More...
 
row_t row () const
 Returns a 1-indexed numeric index of the row of this reference. More...
 
void row (row_t row)
 Sets the row of this reference from a 1-indexed number that identifies a particular row. More...
 
cell_reference make_offset (int column_offset, int row_offset) const
 Returns a cell_reference offset from this cell_reference by the number of columns and rows specified by the parameters. A negative value for column_offset or row_offset results in a reference above or left of this cell_reference, respectively. More...
 
std::string to_string () const
 Returns a string like "A1" for cell_reference(1, 1). More...
 
range_reference to_range () const
 Returns a 1x1 range_reference containing only this cell_reference. More...
 
range_reference operator, (const cell_reference &other) const
 I've always wanted to overload the comma operator. cell_reference("A", 1), cell_reference("B", 1) will return range_reference(cell_reference("A", 1), cell_reference("B", 1)) More...
 
bool operator== (const cell_reference &comparand) const
 Returns true if this reference is identical to comparand including in absoluteness of column and row. More...
 
bool operator== (const std::string &reference_string) const
 Constructs a cell_reference from reference_string and return the result of their comparison. More...
 
bool operator== (const char *reference_string) const
 Constructs a cell_reference from reference_string and return the result of their comparison. More...
 
bool operator!= (const cell_reference &comparand) const
 Returns true if this reference is not identical to comparand including in absoluteness of column and row. More...
 
bool operator!= (const std::string &reference_string) const
 Constructs a cell_reference from reference_string and return the result of their comparison. More...
 
bool operator!= (const char *reference_string) const
 Constructs a cell_reference from reference_string and return the result of their comparison. More...
 

Static Public Member Functions

static std::pair< std::string, row_tsplit_reference (const std::string &reference_string)
 Splits a coordinate string like "A1" into an equivalent pair like {"A", 1}. More...
 
static std::pair< std::string, row_tsplit_reference (const std::string &reference_string, bool &absolute_column, bool &absolute_row)
 Splits a coordinate string like "A1" into an equivalent pair like {"A", 1}. Reference parameters absolute_column and absolute_row will be set to true if column part or row part are prefixed by a dollar-sign indicating they are absolute, otherwise false. More...
 

Detailed Description

An object used to refer to a cell. References have two parts, the column and the row. In Excel, the reference string A1 refers to the top-left-most cell. A cell_reference can be initialized from a string of this form or a 1-indexed ordered pair of the form column, row.

Constructor & Destructor Documentation

◆ cell_reference() [1/4]

xlnt::cell_reference::cell_reference ( )

Default constructor makes a reference to the top-left-most cell, "A1".

◆ cell_reference() [2/4]

xlnt::cell_reference::cell_reference ( const char *  reference_string)

Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14).

◆ cell_reference() [3/4]

xlnt::cell_reference::cell_reference ( const std::string &  reference_string)

Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14).

◆ cell_reference() [4/4]

xlnt::cell_reference::cell_reference ( column_t  column,
row_t  row 
)

Constructs a cell_reference from a 1-indexed column index and row index.

Member Function Documentation

◆ column() [1/2]

column_t xlnt::cell_reference::column ( ) const

Returns a string that identifies the column of this reference (e.g. second column from left is "B")

◆ column() [2/2]

void xlnt::cell_reference::column ( const std::string &  column_string)

Sets the column of this reference from a string that identifies a particular column.

◆ column_absolute() [1/2]

bool xlnt::cell_reference::column_absolute ( ) const

Returns true if the reference refers to an absolute column, otherwise false.

◆ column_absolute() [2/2]

void xlnt::cell_reference::column_absolute ( bool  absolute_column)

Makes this reference have an absolute column if absolute_column is true, otherwise not absolute.

◆ column_index() [1/2]

column_t::index_t xlnt::cell_reference::column_index ( ) const

Returns a 1-indexed numeric index of the column of this reference.

◆ column_index() [2/2]

void xlnt::cell_reference::column_index ( column_t  column)

Sets the column of this reference from a 1-indexed number that identifies a particular column.

◆ make_absolute()

cell_reference& xlnt::cell_reference::make_absolute ( bool  absolute_column = true,
bool  absolute_row = true 
)

Converts a coordinate to an absolute coordinate string (e.g. B12 -> $B$12) Defaulting to true, absolute_column and absolute_row can optionally control whether the resulting cell_reference has an absolute column (e.g. B12 -> $B12) and absolute row (e.g. B12 -> B$12) respectively.

This is functionally equivalent to: cell_reference copy(*this); copy.column_absolute(absolute_column); copy.row_absolute(absolute_row); return copy;

◆ make_offset()

cell_reference xlnt::cell_reference::make_offset ( int  column_offset,
int  row_offset 
) const

Returns a cell_reference offset from this cell_reference by the number of columns and rows specified by the parameters. A negative value for column_offset or row_offset results in a reference above or left of this cell_reference, respectively.

◆ operator!=() [1/3]

bool xlnt::cell_reference::operator!= ( const cell_reference comparand) const

Returns true if this reference is not identical to comparand including in absoluteness of column and row.

◆ operator!=() [2/3]

bool xlnt::cell_reference::operator!= ( const std::string &  reference_string) const

Constructs a cell_reference from reference_string and return the result of their comparison.

◆ operator!=() [3/3]

bool xlnt::cell_reference::operator!= ( const char *  reference_string) const

Constructs a cell_reference from reference_string and return the result of their comparison.

◆ operator,()

range_reference xlnt::cell_reference::operator, ( const cell_reference other) const

I've always wanted to overload the comma operator. cell_reference("A", 1), cell_reference("B", 1) will return range_reference(cell_reference("A", 1), cell_reference("B", 1))

◆ operator==() [1/3]

bool xlnt::cell_reference::operator== ( const cell_reference comparand) const

Returns true if this reference is identical to comparand including in absoluteness of column and row.

◆ operator==() [2/3]

bool xlnt::cell_reference::operator== ( const std::string &  reference_string) const

Constructs a cell_reference from reference_string and return the result of their comparison.

◆ operator==() [3/3]

bool xlnt::cell_reference::operator== ( const char *  reference_string) const

Constructs a cell_reference from reference_string and return the result of their comparison.

◆ row() [1/2]

row_t xlnt::cell_reference::row ( ) const

Returns a 1-indexed numeric index of the row of this reference.

◆ row() [2/2]

void xlnt::cell_reference::row ( row_t  row)

Sets the row of this reference from a 1-indexed number that identifies a particular row.

◆ row_absolute() [1/2]

bool xlnt::cell_reference::row_absolute ( ) const

Returns true if the reference refers to an absolute row, otherwise false.

◆ row_absolute() [2/2]

void xlnt::cell_reference::row_absolute ( bool  absolute_row)

Makes this reference have an absolute row if absolute_row is true, otherwise not absolute.

◆ split_reference() [1/2]

static std::pair<std::string, row_t> xlnt::cell_reference::split_reference ( const std::string &  reference_string)
static

Splits a coordinate string like "A1" into an equivalent pair like {"A", 1}.

◆ split_reference() [2/2]

static std::pair<std::string, row_t> xlnt::cell_reference::split_reference ( const std::string &  reference_string,
bool &  absolute_column,
bool &  absolute_row 
)
static

Splits a coordinate string like "A1" into an equivalent pair like {"A", 1}. Reference parameters absolute_column and absolute_row will be set to true if column part or row part are prefixed by a dollar-sign indicating they are absolute, otherwise false.

◆ to_range()

range_reference xlnt::cell_reference::to_range ( ) const

Returns a 1x1 range_reference containing only this cell_reference.

◆ to_string()

std::string xlnt::cell_reference::to_string ( ) const

Returns a string like "A1" for cell_reference(1, 1).


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