DataRangeEx::Add

Description

Add a new subrange to the DataRangeEx. The subrange is specified by passing an Excel like selection string similar to "[Book1]Sheet1!A[1]:B[2]".


Add a new subrange to the DataRange. The subrange is specified using a Worksheet object and beginning and ending row and column indices.

Syntax

int Add( LPCSTR lpcszRange, LPCSTR lpcszName = NULL )

int Add( Worksheet & wks, int nR1, int nC1, int nR2, int nC2, LPCSTR lpcszName = NULL )

Parameters

lpcszRange
[input]The Excel like range string like "[Book1]Sheet1!A:A"
lpcszName
[input]The name of the subrange like "Range1", "X", "Y" or "ED", if set be NULL, use default string "Range1"

wks
[input]Worksheet in which columns reside
nR1
[input]Row range begin
nC1
[input]Column range begin
nR2
[input]Row range end, use -1 to indicate end of column
nC2
[input]Column range end, if only one column then put in same value as nC1, if to end of worksheet use -1
lpcszName
[input]The name of the subrange like "Range1", "X", "Y" or "ED", if set be NULL, use default string "Range1"

Return

Returns the number of subranges in the DataRangeEx after execution.

Examples

EX1

// This example assumes a worksheet named Sheet1 having two columns named A and B containing XY data
// is the active layer
//Draw a scatter graph with Column A and Column B.
void DataRangeEx_Add_Ex1()
{
    double rr;
    Worksheet wks;
    wks.Create("Origin"); 
    Page pg;
    pg=wks.GetPage();
    if( wks )
    {
        while(wks.Columns(0))
            wks.DeleteCol(0);
        //Create a worksheet with two columns. 
        wks.AddCol("A");
        wks.AddCol("B");
        //Fill the two columns with random data.
        for(int i=0;i<2;i++)
        {
          for(int j=0;j<10;j++)
          {  
                rr=rnd();
                wks.SetCell(j, i, 100*rr);
          }
        }
        
        //Create a DataRangeEx with A,B Columns.
        DataRangeEx dr;
        string strX,strY;
        strX="["+pg.GetName()+"]Sheet1!A:A";
        strY="["+pg.GetName()+"]Sheet1!B:B";
        dr.Add(strX, "X");
        dr.Add(strY, "Y");
 
        GraphPage gp;
        gp.Create("Origin", CREATE_HIDDEN);
        if( gp )
        {
            GraphLayer gl = gp.Layers();
            if( gl )
            {
                //Draw a scatter plot with DataRangeEx.
                gl.AddPlot(dr, IDM_PLOT_SCATTER);
                gl.Rescale();
                gp.SetShow();
            }
        }
    }
}

EX2

//Assume there is a worksheet which has two columns with data.
//Draw a line plot with col(1) and col(2).
void DataRangeEx_Add_Ex2()
{
        Worksheet wks = Project.ActiveLayer();
        //Create a DataRangeEx with xy ranges.
        DataRangeEx dr;
        dr.Add(wks, 0, 0, -1, 0, "X");
        dr.Add(wks, 0, 1, -1, 1, "Y");
        
        GraphPage gp;
    gp.Create("Origin", CREATE_HIDDEN);
    if( gp )
    {
        GraphLayer gl = gp.Layers();
        if( gl )
        {
            //Draw a line plot with DataRangeEx.
            gl.AddPlot(dr, IDM_PLOT_LINE);
            gl.Rescale();
            gp.SetShow();
        }
    }
        
}

Remark

See Also

DataRange::AddInput,DataRange::SetRange

Header to Include

origin.h