2.2.4.46.44 Worksheet::GetSelection

Description

Retrieves the current selection from the worksheet.

Syntax

int GetSelection( int & c1, int & c2, int & r1, int & r2, string * pstrAddress = NULL )

Parameters

c1
[output] Receives the index of the first column in the selection, if any
c2
[output] Receives the index of the last column in the selection, if any
r1
[output] Receives the index of the first row in the selection, if any
r2
[output] Receives the index of the last row in the selection, if any
pstrAddress
[output] if not NULL, pointer to receives the address of the Excel selection range as string (assuming it is an Excel worksheet).
Its default value is NULL.

Return

Integer indicating the type of selection. It can be a bitwise combination of one or more of the following:

WKS_SEL_NONE // no selection

WKS_SEL_EDIT // one cell being edited

WKS_SEL_COLUMN // one or more entire columns selected

WKS_SEL_ROW // one or more entire rows selected

WKS_SEL_RANGE // more than one cell selected

WKS_SEL_ONE_COL // exactly one column selected

WKS_SEL_DISCONTIGUOUS // discontiguous columns selected

WKS_SEL_ALL // entire worksheet

Examples

EX1

int Worksheet_GetSelection_Ex1()
{
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    Worksheet wks(wp.GetName());
    int r1, c1,r2, c2;
    string strAddress;
    int seltype = wks.GetSelection(c1, c2, r1, r2, &strAddress);
    printf("sel = %d\tr1 = %d\tc1 = %d\tr2 = %d\tc2 = %d\n", seltype, r1, c1, r2, c2);
    out_str(strAddress);
    return seltype;
}

Remark

Please note that the argument order is c1,c2,r1,r2 which is not the same as many other function of this type. You may use GetSelectedRange which follows a more consistent argument list of R1C1:R2C2. So this function is provided for backward compatible reason only

See Also

GetSelectedRange, SetSelectedRange

Header to Include

origin.h