Get Set Data Range Selection
Get Data Range Selection
Minimum Origin Version Required: Origin8 SR0
This example shows how to get data range selection in a worksheet.
//Before run this example, make sure you have selected multiple ranges in the active worksheet
void wks_get_datarange_selection_ex()
{
//Make sure the active worksheet has existed
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
vector<int> vr1, vc1, vr2, vc2;
int iRegions = wks.GetSelectedRange(vr1, vc1, vr2, vc2); //get the number of regions
if( 0 == iRegions )
{
printf("No range selected in the active worksheet %s!", wks.GetName());
return;
}
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]);
}
}
Set Data Range Selection
Minimum Origin Version Required: Origin 8 SR0
This example shows how to select specified data range in the worksheet.
void wks_set_datarange_selection_ex()
{
WorksheetPage wp;
wp.Create("Origin");
Worksheet wks;
vector<int> vR1, vC1, vR2, vC2;
bool bRet;
// Full rows selected: only need to specified the row indices
wks = wp.Layers(0);
vR1.SetSize(2);
vR1[0] = 0; //select rows 0
vR1[1] = 3; //select rows 3
bRet = wks.SetSelectedRange(vR1);
if(bRet)
printf("Sussessfully selected range!\n");
else
printf("Failed to select range!\n");
//individual cells selected
wp.AddLayer();
wks = wp.Layers(1);
vR1.SetSize(1);
vR1[0] = 5;
vC1.SetSize(1);
vC1[0] = 0;
bRet = wks.SetSelectedRange(vR1,vC1); //select cell[6:6] in column A
if(bRet)
printf("Sussessfully selected range!\n");
else
printf("Failed to select range!\n");
// partial cols selected
wp.AddLayer();
wks = wp.Layers(2);
vR1.SetSize(1);
vR1[0] = 5;
vC1.SetSize(1);
vC1[0] = 0;
vR2.SetSize(1);
vR2[0] = 20;
bRet = wks.SetSelectedRange(vR1, vC1, vR2); //select cells in column A from the 6th row to the 21th row
if(bRet)
printf("Sussessfully selected range!\n");
else
printf("Failed to select range!\n");
// select several regions
wp.AddLayer();
wks = wp.Layers(3);
vR1.SetSize(2);
vR1[0] = 1;
vR1[1] = 4;
vC1.SetSize(2);
vC1[0] = 0;
vC1[1] = 0;
vR2.SetSize(2);
vR2[0] = 2;
vR2[1] = 5;
vC2.SetSize(2);
vC2[0] = 0;
vC2[1] = 1;
bRet = wks.SetSelectedRange(vR1, vC1, vR2, vC2);
if(bRet)
printf("Sussessfully selected range!\n");
else
printf("Failed to select range!\n");
}
Get Column Label Range
Minimum Origin Version Required: Origin 8.1 SR1
This example shows how to get label range selection
//Before run the following code, make sure the active worksheet exists and select multiple label regions in worksheet
void wks_get_column_label_range_ex()
{
//Make sure the active worksheet has existed
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Error. Please active worksheet before running!");
return;
}
//Create a Grid and attach it to the active worksheet
Grid gg;
gg.Attach(wks);
vector<int> vR1, vC1, vR2, vC2;
BOOL bCheckLabelRows = true;
int iRegions = gg.GetSelection(vR1, vC1, vR2, vC2, bCheckLabelRows);
if( 0 == iRegions )
{
printf("No range selected in the active worksheet %s!", wks.GetName());
return;
}
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]);
}
}
Set Column Label Range
Minimum Origin Version Required: Origin 8 SR0
This example shows how to set ranges a worksheet with label coluum
void wks_set_column_label_Range_ex()
{
WorksheetPage wp;
wp.Create("Origin");
if(!wp)
{
return;
}
Worksheet wks(wp.GetName());
//Create a Grid and attach it to the active worksheet
Grid gg;
gg.Attach(wks);
int nSize = 3; //the number of regions
vector<int> vR1, vC1, vR2, vC2;
vR1.SetSize(nSize);
vR1[0] = 1;
vR1[1] = 5;
vR1[2] = 8;
vC1.SetSize(nSize);
vC1[0] = 1;
vC1[1] = 1;
vC1[2] = 0;
vR2.SetSize(nSize);
vR2[0] = 2;
vR2[1] = 5;
vR2[2] = 8;
vC2.SetSize(nSize);
vC2[0] = 0;
vC2[1] = 1;
vC2[2] = 0;
bool bData = false; //the selections are label regions in worksheet
bool bRet = gg.SetSelection(vR1, vC1, vR2, vC2, bData);
if( bRet )
printf("Successfully Set Selection in %s\n", wks.GetName());
else
printf("Failed to set selection in %s\n", wks.GetName());
}
|