XLL+ Class Library

COper::Cell

Returns a reference to an item in an array

[C++]
COper& Cell(
   USHORT usRow,
   USHORT usCol,
   BOOL bArrayOnly = FALSE
);
const COper& 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 COper does not contain an array; if bArrayOnly is false, then the function returns the COper itself for a non-array COper, 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 = op.GetWidth();
for ( USHORT i = 0; i < usCols; i++ )
{
    const COper& opCell = op.Cell(0, i);
    if ( opCell.IsBool() && !opCell.ToBool() )
        dSum = 0.0;
    else
        dSum += (double)opCell;
}
or, using a pointer:
double dSum = 0.0;
USHORT usCols = op.GetWidth();
COper* popCell;
for ( USHORT i = 0; i < usCols; i++ )
{
    popCell = &op.Cell(0, i);
    if ( popCell->IsBool() && !popCell->ToBool() )
        dSum = 0.0;
    else
        dSum += (double)*popCell;
}

Examples

COper::Cell() Example | MySum Example

Requirements

Header: xllplus.h

See Also

COper Class | COper Methods