2.2.4.46.44 Worksheet::GetSelectedRange

Description

Retrieves the current selection from the worksheet


Retrieves current multiple selection ranges from the worksheet

Syntax

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


int GetSelectedRange( vector<int> & vR1, vector<int> & vC1, vector<int> & vR2, vector<int> & vC2, string * pstrAddress = NULL )

Parameters

r1
[output] Receives the index of the first row in the selection, if any
c1
[output] Receives the index of the first column in the selection, if any
r2
[output] Receives the index of the last row in the selection, if any
c2
[output] Receives the index of the last column 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.


vR1
[output] Receives the vector of indices of the first rows in the selection, if any
vC1
[output] Receives the vector of indices of the first columns in the selection, if any
vR2
[output] Receives the vector of indices of the last rows in the selection, if any
vC2
[output] Receives the vector of indices of the last columns 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


Number of selected regions in worksheet

Examples

EX1

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


EX2

int Worksheet_GetSelectedRange_Ex2()
{
    vector<int> vr1, vc1, vr2, vc2;
    string strRange;
    int iRegions;
    
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    Worksheet wks(wp.GetName());
    iRegions = wks.GetSelectedRange(vr1, vc1, vr2, vc2, strRange);
    for(int ii = 0 ; ii < iRegions ; ii++)
    {
        printf("Region %u : R%d C%d : R%d C%d\n", ii, vr1[ii], vc1[ii], vr2[ii], vc2[ii]);
    }
    printf("Selection : %s\n", strRange);
    return iRegions;
}

Remark

The second overload allows retrieving multiple selection ranges from the worksheet.

See Also

Worksheet::GetSelection, Worksheet::SetSelectedRange, Worksheet::GetSelectedColumns

Header to Include

origin.h