XLL+ Class Library

CXlOper::Cell

Returns a reference to an item in an array

[C++]
CXlOper& Cell(
   USHORT usRow,
   USHORT usCol,
   BOOL bArrayOnly = FALSE
);
const CXlOper& Cell(
   USHORT usRow,
   USHORT usCol,
   BOOL bArrayOnly = FALSE
) const;

Parameters

usRow

The row containing the item of interest (the top row is 0).

usCol

The column containing the item of interest (the leftmost column is 0).

bArrayOnly

If the bArrayOnly parameter is true, then the function asserts if the CXlOper does not contain an array; if bArrayOnly is false, then the function returns the CXlOper itself for a non-array CXlOper, so long as both usRow and usCol = 0.

Remarks

The reference returned by this function can be used to read the item and to update it.

While this is an efficient function (particularly in the release build), for better performance you may wish to hold a pointer or a reference to a cell inside an iteration whenever the cell is repeatedly used, e.g. using a const reference:

double dSum = 0.0;
USHORT usCols = xlo.GetWidth();
for ( USHORT i = 0; i < usCols; i++ )
{
    const CXlOper& xloCell = xlo.Cell(0, i);
    if ( xloCell.IsBool() && !xloCell.ToBool() )
        dSum = 0.0;
    else
        dSum += (double)xloCell;
}
or, using a pointer:
double dSum = 0.0;
USHORT usCols = xlo.GetWidth();
CXlOper* pxloCell;
for ( USHORT i = 0; i < usCols; i++ )
{
    pxloCell = &xlo.Cell(0, i);
    if ( pxloCell->IsBool() && !pxloCell->ToBool() )
        dSum = 0.0;
    else
        dSum += (double)*pxloCell;
}

Examples

CXlOper::GetCallerDims() Example | COper::ReadOpt() Examples | CXlOper::AllocArray() Example | CXlOper::GetCaller() Example | MyMonthsInYear Example

Requirements

Header: xllplus.h

See Also

CXlOper Class | CXlOper Methods