wxAutoExcel 2.5.1
Loading...
Searching...
No Matches
wxAutoExcel::wxExcelRangeData Class Reference

A rectangular block of the values or formulas of range cells. More...

#include <wxAutoExcelRangeData.h>

Public Member Functions

 wxExcelRangeData (size_t rows=0, size_t columns=0)
 Creates data of the given size, with all cells empty.
size_t GetRowCount () const
 Returns the number of rows.
size_t GetColumnCount () const
 Returns the number of columns.
bool IsEmpty () const
 Returns true if the data have no cells.
void Resize (size_t rows, size_t columns)
 Changes the size.
void Clear ()
 Removes all the cells.
wxVariant & operator() (size_t row, size_t column)
 Returns the cell in the given row and column, numbered from 0.
bool GetCell (size_t row, size_t column, double &value) const
 Gets the value of the cell in the given row and column, numbered from 0, when the cell contains a value of the type of value.
bool IsCellEmpty (size_t row, size_t column) const
 Returns true if the cell in the given row and column, numbered from 0, is empty.
bool IsCellError (size_t row, size_t column, XlCVError *error=NULL) const
 Returns true if the cell in the given row and column, numbered from 0, contains an error value, such as #N/A or #DIV/0!
wxVector< wxVariant > GetRow (size_t row) const
 Returns the cells of the given row, numbered from 0.
wxVector< wxVariant > GetColumn (size_t column) const
 Returns the cells of the given column, numbered from 0.
wxVariant ToVariant () const
 Converts the data to a wxVariant containing a two-dimensional SAFEARRAY of VARIANTs, which can be passed e.g.

Static Public Member Functions

static bool FromVariant (const wxVariant &value, wxExcelRangeData &data)
 Sets data from the value of a range returned by Excel, which is a two-dimensional SAFEARRAY of VARIANTs for a range with more than one cell, or a single value for a single cell.

Detailed Description

A rectangular block of the values or formulas of range cells.

The rows and columns are numbered from 0, so that the cell in the top left corner of the range is (0, 0). Each cell is a wxVariant, which is null for an empty cell, a double for a number, a string, a bool, a wxDateTime for a date (when not obtained with Value2), or a wxVariantDataErrorCode for an error value.

Use wxExcelRange::GetValues_() and wxExcelRange::SetValues_(), or wxExcelRange::GetFormulas_() and wxExcelRange::SetFormulas_() to transfer the data at once, which is much faster than cell by cell:

// range is a valid wxExcelRange of 3 rows and 2 columns
wxExcelRangeData data(3, 2);
for ( size_t row = 0; row < data.GetRowCount(); ++row )
{
data(row, 0) = wxString::Format("Item %d", static_cast<int>(row) + 1);
data(row, 1) = 10.0 * row;
}
if ( !range.SetValues_(data) )
wxLogError(_("Failed to set the values."));
wxExcelRangeData(size_t rows=0, size_t columns=0)
Creates data of the given size, with all cells empty.

Constructor & Destructor Documentation

◆ wxExcelRangeData()

wxAutoExcel::wxExcelRangeData::wxExcelRangeData ( size_t rows = 0,
size_t columns = 0 )

Creates data of the given size, with all cells empty.

Member Function Documentation

◆ GetRowCount()

size_t wxAutoExcel::wxExcelRangeData::GetRowCount ( ) const
inline

Returns the number of rows.

◆ GetColumnCount()

size_t wxAutoExcel::wxExcelRangeData::GetColumnCount ( ) const
inline

Returns the number of columns.

◆ IsEmpty()

bool wxAutoExcel::wxExcelRangeData::IsEmpty ( ) const
inline

Returns true if the data have no cells.

◆ Resize()

void wxAutoExcel::wxExcelRangeData::Resize ( size_t rows,
size_t columns )

Changes the size.

The cells which remain keep their values, the new cells are empty.

◆ Clear()

void wxAutoExcel::wxExcelRangeData::Clear ( )

Removes all the cells.

◆ operator()()

wxVariant & wxAutoExcel::wxExcelRangeData::operator() ( size_t row,
size_t column )

Returns the cell in the given row and column, numbered from 0.

◆ GetCell()

bool wxAutoExcel::wxExcelRangeData::GetCell ( size_t row,
size_t column,
double & value ) const

Gets the value of the cell in the given row and column, numbered from 0, when the cell contains a value of the type of value.

Otherwise, returns false, leaving value unchanged.

The values are not converted between the types, except for numbers:

  • a double is obtained from any number, including a currency value;
  • a long is obtained from a number which is a whole number in the range of long.

Excel provides dates as wxDateTime only when obtained with Value, see wxExcelRange::GetValues_(), with Value2 they are numbers.

◆ IsCellEmpty()

bool wxAutoExcel::wxExcelRangeData::IsCellEmpty ( size_t row,
size_t column ) const

Returns true if the cell in the given row and column, numbered from 0, is empty.

◆ IsCellError()

bool wxAutoExcel::wxExcelRangeData::IsCellError ( size_t row,
size_t column,
XlCVError * error = NULL ) const

Returns true if the cell in the given row and column, numbered from 0, contains an error value, such as #N/A or #DIV/0!

. If error is not NULL, it is set to the error value.

◆ GetRow()

wxVector< wxVariant > wxAutoExcel::wxExcelRangeData::GetRow ( size_t row) const

Returns the cells of the given row, numbered from 0.

◆ GetColumn()

wxVector< wxVariant > wxAutoExcel::wxExcelRangeData::GetColumn ( size_t column) const

Returns the cells of the given column, numbered from 0.

◆ ToVariant()

wxVariant wxAutoExcel::wxExcelRangeData::ToVariant ( ) const

Converts the data to a wxVariant containing a two-dimensional SAFEARRAY of VARIANTs, which can be passed e.g.

to wxExcelRange::SetValue(). Returns a null wxVariant when the data are empty.

The SAFEARRAY is destroyed when the wxVariant is passed to an automation call, otherwise the caller must destroy it with SafeArrayDestroy().

◆ FromVariant()

bool wxAutoExcel::wxExcelRangeData::FromVariant ( const wxVariant & value,
wxExcelRangeData & data )
static

Sets data from the value of a range returned by Excel, which is a two-dimensional SAFEARRAY of VARIANTs for a range with more than one cell, or a single value for a single cell.

A SAFEARRAY is not destroyed. Returns false, leaving data empty, when value is a SAFEARRAY of another type or with another number of dimensions, or a list, which has no dimensions.