xlnt
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
xlnt::cell Class Reference

Describes a unit of data in a worksheet at a specific coordinate and its associated properties. More...

#include <cell.hpp>

Public Types

using type = cell_type
 Alias xlnt::cell_type to xlnt::cell::type since it looks nicer. More...
 

Public Member Functions

 cell (const cell &)=default
 Default copy constructor. More...
 
bool has_value () const
 Returns true if value has been set and has not been cleared using cell::clear_value(). More...
 
template<typename T >
value () const
 Returns the value of this cell as an instance of type T. Overloads exist for most C++ fundamental types like bool, int, etc. as well as for std::string and xlnt datetime types: date, time, datetime, and timedelta. More...
 
void clear_value ()
 Makes this cell have a value of type null. All other cell attributes are retained. More...
 
void value (std::nullptr_t)
 Sets the type of this cell to null. More...
 
void value (bool boolean_value)
 Sets the value of this cell to the given boolean value. More...
 
void value (int int_value)
 Sets the value of this cell to the given value. More...
 
void value (unsigned int int_value)
 Sets the value of this cell to the given value. More...
 
void value (long long int int_value)
 Sets the value of this cell to the given value. More...
 
void value (unsigned long long int int_value)
 Sets the value of this cell to the given value. More...
 
void value (float float_value)
 Sets the value of this cell to the given value. More...
 
void value (double float_value)
 Sets the value of this cell to the given value. More...
 
void value (const date &date_value)
 Sets the value of this cell to the given value. More...
 
void value (const time &time_value)
 Sets the value of this cell to the given value. More...
 
void value (const datetime &datetime_value)
 Sets the value of this cell to the given value. More...
 
void value (const timedelta &timedelta_value)
 Sets the value of this cell to the given value. More...
 
void value (const std::string &string_value)
 Sets the value of this cell to the given value. More...
 
void value (const char *string_value)
 Sets the value of this cell to the given value. More...
 
void value (const rich_text &text_value)
 Sets the value of this cell to the given value. More...
 
void value (const cell other_cell)
 Sets the value and formatting of this cell to that of other_cell. More...
 
void value (const std::string &string_value, bool infer_type)
 Analyzes string_value to determine its type, convert it to that type, and set the value of this cell to that converted value. More...
 
type data_type () const
 Returns the type of this cell. More...
 
void data_type (type t)
 Sets the type of this cell. This should usually be done indirectly by setting the value of the cell to a value of that type. More...
 
bool garbage_collectible () const
 There's no reason to keep a cell which has no value and is not a placeholder. Returns true if this cell has no value, style, isn't merged, etc. More...
 
bool is_date () const
 Returns true iff this cell's number format matches a date format. More...
 
cell_reference reference () const
 Returns a cell_reference that points to the location of this cell. More...
 
column_t column () const
 Returns the column of this cell. More...
 
column_t::index_t column_index () const
 Returns the numeric index (A == 1) of the column of this cell. More...
 
row_t row () const
 Returns the row of this cell. More...
 
std::pair< int, int > anchor () const
 Returns the location of this cell as an ordered pair (left, top). More...
 
class hyperlink hyperlink () const
 Returns the relationship of this cell's hyperlink. More...
 
void hyperlink (const std::string &url, const std::string &display="")
 Adds a hyperlink to this cell pointing to the URI of the given value and sets the text value of the cell to the given parameter. More...
 
void hyperlink (xlnt::cell target, const std::string &display="")
 Adds an internal hyperlink to this cell pointing to the given cell. More...
 
void hyperlink (xlnt::range target, const std::string &display="")
 Adds an internal hyperlink to this cell pointing to the given range. More...
 
bool has_hyperlink () const
 Returns true if this cell has a hyperlink set. More...
 
class alignment computed_alignment () const
 Returns the alignment that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
class border computed_border () const
 Returns the border that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
class fill computed_fill () const
 Returns the fill that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
class font computed_font () const
 Returns the font that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
class number_format computed_number_format () const
 Returns the number format that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
class protection computed_protection () const
 Returns the protection that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order. More...
 
bool has_format () const
 Returns true if this cell has had a format applied to it. More...
 
const class format format () const
 Returns the format applied to this cell. If this cell has no format, an invalid_attribute exception will be thrown. More...
 
void format (const class format new_format)
 Applies the cell-level formatting of new_format to this cell. More...
 
void clear_format ()
 Removes the cell-level formatting from this cell. This doesn't affect the style that may also be applied to the cell. Throws an invalid_attribute exception if no format is applied. More...
 
class number_format number_format () const
 Returns the number format of this cell. More...
 
void number_format (const class number_format &format)
 Creates a new format in the workbook, sets its number_format to the given format, and applies the format to this cell. More...
 
class font font () const
 Returns the font applied to the text in this cell. More...
 
void font (const class font &font_)
 Creates a new format in the workbook, sets its font to the given font, and applies the format to this cell. More...
 
class fill fill () const
 Returns the fill applied to this cell. More...
 
void fill (const class fill &fill_)
 Creates a new format in the workbook, sets its fill to the given fill, and applies the format to this cell. More...
 
class border border () const
 Returns the border of this cell. More...
 
void border (const class border &border_)
 Creates a new format in the workbook, sets its border to the given border, and applies the format to this cell. More...
 
class alignment alignment () const
 Returns the alignment of the text in this cell. More...
 
void alignment (const class alignment &alignment_)
 Creates a new format in the workbook, sets its alignment to the given alignment, and applies the format to this cell. More...
 
class protection protection () const
 Returns the protection of this cell. More...
 
void protection (const class protection &protection_)
 Creates a new format in the workbook, sets its protection to the given protection, and applies the format to this cell. More...
 
bool has_style () const
 Returns true if this cell has had a style applied to it. More...
 
class style style ()
 Returns a wrapper pointing to the named style applied to this cell. More...
 
const class style style () const
 Returns a wrapper pointing to the named style applied to this cell. More...
 
void style (const class style &new_style)
 Sets the named style applied to this cell to a style named style_name. Equivalent to style(new_style.name()). More...
 
void style (const std::string &style_name)
 Sets the named style applied to this cell to a style named style_name. If this style has not been previously created in the workbook, a key_not_found exception will be thrown. More...
 
void clear_style ()
 Removes the named style from this cell. An invalid_attribute exception will be thrown if this cell has no style. This will not affect the cell format of the cell. More...
 
std::string formula () const
 Returns the string representation of the formula applied to this cell. More...
 
void formula (const std::string &formula)
 Sets the formula of this cell to the given value. This formula string should begin with '='. More...
 
void clear_formula ()
 Removes the formula from this cell. After this is called, has_formula() will return false. More...
 
bool has_formula () const
 Returns true if this cell has had a formula applied to it. More...
 
std::string to_string () const
 Returns a string representing the value of this cell. If the data type is not a string, it will be converted according to the number format. More...
 
bool is_merged () const
 Returns true iff this cell has been merged with one or more surrounding cells. More...
 
void merged (bool merged)
 Makes this a merged cell iff merged is true. Generally, this shouldn't be called directly. Instead, use worksheet::merge_cells on its parent worksheet. More...
 
bool phonetics_visible () const
 Returns true if this cell is set to show phonetic information. More...
 
void show_phonetics (bool phonetics)
 Enables the display of phonetic information on this cell. More...
 
std::string error () const
 Returns the error string that is stored in this cell. More...
 
void error (const std::string &error)
 Directly assigns the value of this cell to be the given error. More...
 
cell offset (int column, int row)
 Returns a cell from this cell's parent workbook at a relative offset given by the parameters. More...
 
class worksheet worksheet ()
 Returns the worksheet that owns this cell. More...
 
const class worksheet worksheet () const
 Returns the worksheet that owns this cell. More...
 
class workbookworkbook ()
 Returns the workbook of the worksheet that owns this cell. More...
 
const class workbookworkbook () const
 Returns the workbook of the worksheet that owns this cell. More...
 
calendar base_date () const
 Returns the base date of the parent workbook. More...
 
std::string check_string (const std::string &to_check)
 Returns to_check after verifying and fixing encoding, size, and illegal characters. More...
 
bool has_comment ()
 Returns true if this cell has a comment applied. More...
 
void clear_comment ()
 Deletes the comment applied to this cell if it exists. More...
 
class comment comment ()
 Gets the comment applied to this cell. More...
 
void comment (const std::string &text, const std::string &author="Microsoft Office User")
 Creates a new comment with the given text and optional author and applies it to the cell. More...
 
void comment (const std::string &comment_text, const class font &comment_font, const std::string &author="Microsoft Office User")
 Creates a new comment with the given text, formatting, and optional author and applies it to the cell. More...
 
void comment (const class comment &new_comment)
 Apply the comment provided as the only argument to the cell. More...
 
double width () const
 Returns the width of this cell in pixels. More...
 
double height () const
 Returns the height of this cell in pixels. More...
 
celloperator= (const cell &rhs)
 Makes this cell interally point to rhs. The cell data originally pointed to by this cell will be unchanged. More...
 
bool operator== (const cell &comparand) const
 Returns true if this cell the same cell as comparand (compared by reference). More...
 
bool operator!= (const cell &comparand) const
 Returns false if this cell the same cell as comparand (compared by reference). More...
 
template<>
bool value () const
 
template<>
int value () const
 
template<>
unsigned int value () const
 
template<>
long long int value () const
 
template<>
unsigned long long value () const
 
template<>
float value () const
 
template<>
double value () const
 
template<>
date value () const
 
template<>
time value () const
 
template<>
datetime value () const
 
template<>
timedelta value () const
 
template<>
rich_text value () const
 

Static Public Member Functions

static const std::unordered_map< std::string, int > & error_codes ()
 Returns a map of error strings such as #DIV/0! and their associated indices. More...
 

Friends

class style
 
class worksheet
 
class detail::xlsx_consumer
 
class detail::xlsx_producer
 
struct detail::cell_impl
 

Detailed Description

Describes a unit of data in a worksheet at a specific coordinate and its associated properties.

Properties of interest include style, type, value, and address. The Cell class is required to know its value and type, display options, and any other features of an Excel cell.Utilities for referencing cells using Excel's 'A1' column/row nomenclature are also provided.

Member Typedef Documentation

◆ type

Alias xlnt::cell_type to xlnt::cell::type since it looks nicer.

Constructor & Destructor Documentation

◆ cell()

xlnt::cell::cell ( const cell )
default

Default copy constructor.

Member Function Documentation

◆ alignment() [1/2]

class alignment xlnt::cell::alignment ( ) const

Returns the alignment of the text in this cell.

◆ alignment() [2/2]

void xlnt::cell::alignment ( const class alignment alignment_)

Creates a new format in the workbook, sets its alignment to the given alignment, and applies the format to this cell.

◆ anchor()

std::pair<int, int> xlnt::cell::anchor ( ) const

Returns the location of this cell as an ordered pair (left, top).

◆ base_date()

calendar xlnt::cell::base_date ( ) const

Returns the base date of the parent workbook.

◆ border() [1/2]

class border xlnt::cell::border ( ) const

Returns the border of this cell.

◆ border() [2/2]

void xlnt::cell::border ( const class border border_)

Creates a new format in the workbook, sets its border to the given border, and applies the format to this cell.

◆ check_string()

std::string xlnt::cell::check_string ( const std::string &  to_check)

Returns to_check after verifying and fixing encoding, size, and illegal characters.

◆ clear_comment()

void xlnt::cell::clear_comment ( )

Deletes the comment applied to this cell if it exists.

◆ clear_format()

void xlnt::cell::clear_format ( )

Removes the cell-level formatting from this cell. This doesn't affect the style that may also be applied to the cell. Throws an invalid_attribute exception if no format is applied.

◆ clear_formula()

void xlnt::cell::clear_formula ( )

Removes the formula from this cell. After this is called, has_formula() will return false.

◆ clear_style()

void xlnt::cell::clear_style ( )

Removes the named style from this cell. An invalid_attribute exception will be thrown if this cell has no style. This will not affect the cell format of the cell.

◆ clear_value()

void xlnt::cell::clear_value ( )

Makes this cell have a value of type null. All other cell attributes are retained.

◆ column()

column_t xlnt::cell::column ( ) const

Returns the column of this cell.

◆ column_index()

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

Returns the numeric index (A == 1) of the column of this cell.

◆ comment() [1/4]

class comment xlnt::cell::comment ( )

Gets the comment applied to this cell.

◆ comment() [2/4]

void xlnt::cell::comment ( const std::string &  text,
const std::string &  author = "Microsoft Office User" 
)

Creates a new comment with the given text and optional author and applies it to the cell.

◆ comment() [3/4]

void xlnt::cell::comment ( const std::string &  comment_text,
const class font comment_font,
const std::string &  author = "Microsoft Office User" 
)

Creates a new comment with the given text, formatting, and optional author and applies it to the cell.

◆ comment() [4/4]

void xlnt::cell::comment ( const class comment new_comment)

Apply the comment provided as the only argument to the cell.

◆ computed_alignment()

class alignment xlnt::cell::computed_alignment ( ) const

Returns the alignment that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ computed_border()

class border xlnt::cell::computed_border ( ) const

Returns the border that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ computed_fill()

class fill xlnt::cell::computed_fill ( ) const

Returns the fill that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ computed_font()

class font xlnt::cell::computed_font ( ) const

Returns the font that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ computed_number_format()

class number_format xlnt::cell::computed_number_format ( ) const

Returns the number format that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ computed_protection()

class protection xlnt::cell::computed_protection ( ) const

Returns the protection that should be used when displaying this cell graphically based on the workbook default, the cell-level format, and the named style applied to the cell in that order.

◆ data_type() [1/2]

type xlnt::cell::data_type ( ) const

Returns the type of this cell.

◆ data_type() [2/2]

void xlnt::cell::data_type ( type  t)

Sets the type of this cell. This should usually be done indirectly by setting the value of the cell to a value of that type.

◆ error() [1/2]

std::string xlnt::cell::error ( ) const

Returns the error string that is stored in this cell.

◆ error() [2/2]

void xlnt::cell::error ( const std::string &  error)

Directly assigns the value of this cell to be the given error.

◆ error_codes()

static const std::unordered_map<std::string, int>& xlnt::cell::error_codes ( )
static

Returns a map of error strings such as #DIV/0! and their associated indices.

◆ fill() [1/2]

class fill xlnt::cell::fill ( ) const

Returns the fill applied to this cell.

◆ fill() [2/2]

void xlnt::cell::fill ( const class fill fill_)

Creates a new format in the workbook, sets its fill to the given fill, and applies the format to this cell.

◆ font() [1/2]

class font xlnt::cell::font ( ) const

Returns the font applied to the text in this cell.

◆ font() [2/2]

void xlnt::cell::font ( const class font font_)

Creates a new format in the workbook, sets its font to the given font, and applies the format to this cell.

◆ format() [1/2]

const class format xlnt::cell::format ( ) const

Returns the format applied to this cell. If this cell has no format, an invalid_attribute exception will be thrown.

◆ format() [2/2]

void xlnt::cell::format ( const class format  new_format)

Applies the cell-level formatting of new_format to this cell.

◆ formula() [1/2]

std::string xlnt::cell::formula ( ) const

Returns the string representation of the formula applied to this cell.

◆ formula() [2/2]

void xlnt::cell::formula ( const std::string &  formula)

Sets the formula of this cell to the given value. This formula string should begin with '='.

◆ garbage_collectible()

bool xlnt::cell::garbage_collectible ( ) const

There's no reason to keep a cell which has no value and is not a placeholder. Returns true if this cell has no value, style, isn't merged, etc.

◆ has_comment()

bool xlnt::cell::has_comment ( )

Returns true if this cell has a comment applied.

◆ has_format()

bool xlnt::cell::has_format ( ) const

Returns true if this cell has had a format applied to it.

◆ has_formula()

bool xlnt::cell::has_formula ( ) const

Returns true if this cell has had a formula applied to it.

◆ has_hyperlink()

bool xlnt::cell::has_hyperlink ( ) const

Returns true if this cell has a hyperlink set.

◆ has_style()

bool xlnt::cell::has_style ( ) const

Returns true if this cell has had a style applied to it.

◆ has_value()

bool xlnt::cell::has_value ( ) const

Returns true if value has been set and has not been cleared using cell::clear_value().

◆ height()

double xlnt::cell::height ( ) const

Returns the height of this cell in pixels.

◆ hyperlink() [1/4]

class hyperlink xlnt::cell::hyperlink ( ) const

Returns the relationship of this cell's hyperlink.

◆ hyperlink() [2/4]

void xlnt::cell::hyperlink ( const std::string &  url,
const std::string &  display = "" 
)

Adds a hyperlink to this cell pointing to the URI of the given value and sets the text value of the cell to the given parameter.

◆ hyperlink() [3/4]

void xlnt::cell::hyperlink ( xlnt::cell  target,
const std::string &  display = "" 
)

Adds an internal hyperlink to this cell pointing to the given cell.

◆ hyperlink() [4/4]

void xlnt::cell::hyperlink ( xlnt::range  target,
const std::string &  display = "" 
)

Adds an internal hyperlink to this cell pointing to the given range.

◆ is_date()

bool xlnt::cell::is_date ( ) const

Returns true iff this cell's number format matches a date format.

◆ is_merged()

bool xlnt::cell::is_merged ( ) const

Returns true iff this cell has been merged with one or more surrounding cells.

◆ merged()

void xlnt::cell::merged ( bool  merged)

Makes this a merged cell iff merged is true. Generally, this shouldn't be called directly. Instead, use worksheet::merge_cells on its parent worksheet.

◆ number_format() [1/2]

class number_format xlnt::cell::number_format ( ) const

Returns the number format of this cell.

◆ number_format() [2/2]

void xlnt::cell::number_format ( const class number_format format)

Creates a new format in the workbook, sets its number_format to the given format, and applies the format to this cell.

◆ offset()

cell xlnt::cell::offset ( int  column,
int  row 
)

Returns a cell from this cell's parent workbook at a relative offset given by the parameters.

◆ operator!=()

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

Returns false if this cell the same cell as comparand (compared by reference).

◆ operator=()

cell& xlnt::cell::operator= ( const cell rhs)

Makes this cell interally point to rhs. The cell data originally pointed to by this cell will be unchanged.

◆ operator==()

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

Returns true if this cell the same cell as comparand (compared by reference).

◆ phonetics_visible()

bool xlnt::cell::phonetics_visible ( ) const

Returns true if this cell is set to show phonetic information.

◆ protection() [1/2]

class protection xlnt::cell::protection ( ) const

Returns the protection of this cell.

◆ protection() [2/2]

void xlnt::cell::protection ( const class protection protection_)

Creates a new format in the workbook, sets its protection to the given protection, and applies the format to this cell.

◆ reference()

cell_reference xlnt::cell::reference ( ) const

Returns a cell_reference that points to the location of this cell.

◆ row()

row_t xlnt::cell::row ( ) const

Returns the row of this cell.

◆ show_phonetics()

void xlnt::cell::show_phonetics ( bool  phonetics)

Enables the display of phonetic information on this cell.

◆ style() [1/4]

class style xlnt::cell::style ( )

Returns a wrapper pointing to the named style applied to this cell.

◆ style() [2/4]

const class style xlnt::cell::style ( ) const

Returns a wrapper pointing to the named style applied to this cell.

◆ style() [3/4]

void xlnt::cell::style ( const class style new_style)

Sets the named style applied to this cell to a style named style_name. Equivalent to style(new_style.name()).

◆ style() [4/4]

void xlnt::cell::style ( const std::string &  style_name)

Sets the named style applied to this cell to a style named style_name. If this style has not been previously created in the workbook, a key_not_found exception will be thrown.

◆ to_string()

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

Returns a string representing the value of this cell. If the data type is not a string, it will be converted according to the number format.

◆ value() [1/18]

template<typename T >
T xlnt::cell::value ( ) const

Returns the value of this cell as an instance of type T. Overloads exist for most C++ fundamental types like bool, int, etc. as well as for std::string and xlnt datetime types: date, time, datetime, and timedelta.

◆ value() [2/18]

void xlnt::cell::value ( std::nullptr_t  )

Sets the type of this cell to null.

◆ value() [3/18]

void xlnt::cell::value ( bool  boolean_value)

Sets the value of this cell to the given boolean value.

◆ value() [4/18]

void xlnt::cell::value ( int  int_value)

Sets the value of this cell to the given value.

◆ value() [5/18]

void xlnt::cell::value ( unsigned int  int_value)

Sets the value of this cell to the given value.

◆ value() [6/18]

void xlnt::cell::value ( long long int  int_value)

Sets the value of this cell to the given value.

◆ value() [7/18]

void xlnt::cell::value ( unsigned long long int  int_value)

Sets the value of this cell to the given value.

◆ value() [8/18]

void xlnt::cell::value ( float  float_value)

Sets the value of this cell to the given value.

◆ value() [9/18]

void xlnt::cell::value ( double  float_value)

Sets the value of this cell to the given value.

◆ value() [10/18]

void xlnt::cell::value ( const date date_value)

Sets the value of this cell to the given value.

◆ value() [11/18]

void xlnt::cell::value ( const time time_value)

Sets the value of this cell to the given value.

◆ value() [12/18]

void xlnt::cell::value ( const datetime datetime_value)

Sets the value of this cell to the given value.

◆ value() [13/18]

void xlnt::cell::value ( const timedelta timedelta_value)

Sets the value of this cell to the given value.

◆ value() [14/18]

void xlnt::cell::value ( const std::string &  string_value)

Sets the value of this cell to the given value.

◆ value() [15/18]

void xlnt::cell::value ( const char *  string_value)

Sets the value of this cell to the given value.

◆ value() [16/18]

void xlnt::cell::value ( const rich_text text_value)

Sets the value of this cell to the given value.

◆ value() [17/18]

void xlnt::cell::value ( const cell  other_cell)

Sets the value and formatting of this cell to that of other_cell.

◆ value() [18/18]

void xlnt::cell::value ( const std::string &  string_value,
bool  infer_type 
)

Analyzes string_value to determine its type, convert it to that type, and set the value of this cell to that converted value.

◆ width()

double xlnt::cell::width ( ) const

Returns the width of this cell in pixels.

◆ workbook() [1/2]

class workbook& xlnt::cell::workbook ( )

Returns the workbook of the worksheet that owns this cell.

◆ workbook() [2/2]

const class workbook& xlnt::cell::workbook ( ) const

Returns the workbook of the worksheet that owns this cell.

◆ worksheet() [1/2]

const class worksheet xlnt::cell::worksheet ( ) const

Returns the worksheet that owns this cell.

◆ worksheet() [2/2]

class worksheet xlnt::cell::worksheet ( )

Returns the worksheet that owns this cell.


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