DataRange::GetRange

Description

Get one single range's data.

Syntax

BOOL GetRange( int nIndex, int & r1, int & c1, int & r2, int & c2, Datasheet & ds, string * pstrName = NULL )const

BOOL GetRange( Datasheet & ds, int & c1, int & c2, int nIndex = 0 )

int GetRange( LPCTSTR lpcszName, int & r1, int & c1, int & r2, int & c2, Datasheet & ds )const

Parameters

nIndex
[input]the index of the data. DataRange can reference multiple sets of data. Index starts from 0.
r1
[output]minimum begining row index (0 based)
c1
[output]begining column index (0 based)
r2
[output]maximum ending row index (0 based)
c2
[output]ending column index (0 based)
ds
[output]the datasheet that contained the datarange
pstrName
[output]the name of the subrange

ds
[output]the datasheet that contained the datarange
c1
[output]begining column index (0 based)
c2
[output]ending column index (0 based)
nIndex

lpcszName
[input]the name of the DataRange
r1
[output]Output minimum begining row index (0 based)
c1
[output]Output the begining column index (0 based offset)
r2
[output]Output maximum ending row index (0 based)
c2
[output]Output the ending column index (0 based offset)
ds
[output]the datasheet that contained the datarange

Return

Returns TRUE for success or FALSE for failure

Returns TRUE for success or FALSE for failure

Returns the index of the subrange if successful else returns -1

Examples

EX1

//This example will output the min and max value of the X,Y column.
void DataRange_GetRange_Ex1(int nCol1 = 0, int nCol2 = 1)
{
    Worksheet wks;
    wks.Create();
    if( wks )
    {
        while(wks.Columns(0))
            wks.DeleteCol(0);

        wks.AddCol("A");
        wks.AddCol("B");
        string strX,strY;
        strX="A";
        strY="B";
        double rr;
        for(int j=0;j<2;j++)
        {
            for (int i=0;i<10;i++)
            {
                   rr=rnd();
                   wks.SetCell(i,j,rr*100);
            }
        }
            
        DataRange dr;
        dr.Add("X", wks, 0, nCol1, -1, nCol1);
        dr.Add("Y", wks, 0, nCol2, -1, nCol2);
        vector vData;
        DWORD dwPlotID;
        int ii, r1, c1, r2, c2;
        Worksheet MyWks;
        string strRange;
        double dmin, dmax;

        ii = dr.GetData(DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vData);
        dr.GetRange(0, r1, c1, r2, c2, MyWks, &strRange);
        vData.GetMinMax(dmin, dmax);
        printf("\nRange '%s': [%s]%s r1 = %d c1 = %d r2 = %d c2 = %d\nmin = %g max = %g\n",
                strRange, MyWks.GetPage().GetName(), MyWks.GetName(), r1, c1, r2, c2, dmin, dmax);

        ii = dr.GetData(DRR_NO_FACTORS| DRR_GET_DEPENDENT, 0, &dwPlotID, NULL, &vData);
        dr.GetRange(1, r1, c1, r2, c2, MyWks, &strRange);
        vData.GetMinMax(dmin, dmax);
        printf("\nRange '%s': [%s]%s r1 = %d c1 = %d r2 = %d c2 = %d\nmin = %g max = %g\n",
                strRange, MyWks.GetPage().GetName(), MyWks.GetName(), r1, c1, r2, c2, dmin, dmax);
    }
}


EX2

//This example will output the min and max value of the X,Y column.
void DataRange_GetRange_Ex2(int nCol1 = 0, int nCol2 = 1)
{
    Worksheet wks ;
    wks.Create();
    if( wks )
    {
        while(wks.Columns(0))
            wks.DeleteCol(0);

        wks.AddCol("A");
        wks.AddCol("B");
        double rr;
        for(int j=0;j<2;j++)
        {
            for (int i=0;i<10;i++)
            {
                   rr=rnd();
                   wks.SetCell(i,j,rr*100);
            }
        }
        DataRange dr;
        dr.Add("X", wks, 0, nCol1, -1, nCol1);
        dr.Add("Y", wks, 0, nCol2, -1, nCol2);
        vector vData;
        DWORD dwPlotID;
        int ii, r1, c1, r2, c2;
        Worksheet MyWks;
        string strRange;
        double dmin, dmax;

        ii = dr.GetData(DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vData);
        strRange = "X";
        dr.GetRange(strRange, r1, c1, r2, c2, MyWks);
        vData.GetMinMax(dmin, dmax);
        printf("\nRange '%s': [%s]%s r1 = %d c1 = %d r2 = %d c2 = %d\nmin = %g max = %g\n",
                strRange, MyWks.GetPage().GetName(), MyWks.GetName(), r1, c1, r2, c2, dmin, dmax);

        ii = dr.GetData(DRR_NO_FACTORS| DRR_GET_DEPENDENT, 0, &dwPlotID, NULL, &vData);
        strRange = "Y";
        dr.GetRange(strRange, r1, c1, r2, c2, MyWks);
        vData.GetMinMax(dmin, dmax);
        printf("\nRange '%s': [%s]%s r1 = %d c1 = %d r2 = %d c2 = %d\nmin = %g max = %g\n",
                strRange, MyWks.GetPage().GetName(), MyWks.GetName(), r1, c1, r2, c2, dmin, dmax);
    }
}

EX3

//Output the datarange's beginning column index and ending column index.
DataRange_GetRange_Ex2()
{
        //Create a worsheet and add two columns.
        Worksheet wks;
        wks.Create();
        wks.AddCol();
        wks.AddCol();
        
        //Create a datarange with two subranges.
        DataRange dr;
        int nCol1 = 0;
        int nCol2 = 1;;
        dr.Add("Range1", wks, 0, nCol1, -1, nCol2);
        nCol1 = 2;
        nCol2 = 3;
        dr.Add("Range2", wks, 0, nCol1, -1, nCol2);
        
        int c1, c2;
        dr.GetRange(wks, c1, c2, 0);
        //output the first subrange's beginning column and ending column index.
        printf("Range1: [%s]%s c1 = %d c2 = %d\n", wks.GetPage().GetName(), wks.GetName(), c1, c2);
        
        dr.GetRange(wks, c1, c2, 1);
        //output the second subrange's beginning column and ending column index.
        printf("Range2: [%s]%s c1 = %d c2 = %d\n", wks.GetPage().GetName(), wks.GetName(), c1, c2);
        
}

Remark

See Also

DataRange::GetSubRange

header to Include

origin.h