3.2.7.7 Worksheet Get Label Contents
The following examples show how to get one whole label contents from Worksheet by row index, label type or label name.
Get Label Contents by Label Type
Minimum Origin Version Required: Origin 8.1 SR0
Label type (RCLT_*) defined in oc_const.h file ROWCOLLABELTYPE enum.
Worksheet wks;
wks = Project.ActiveLayer();
Grid gg;
gg.Attach(wks);
vector<string> vstr;
int nLabelType = RCLT_UDL; // "UDL" means User Defined Label type
gg.GetLabelsByType(vstr, nLabelType);
out_int("size=", vstr.GetSize());
// convert string vector to double vector
vector vv;
convert_str_vector_to_num_vector(vstr, vv);
out_int("size=", vv.GetSize());
Get Label Contents by Row Index
Minimum Origin Version Required: Origin 8.0 SR0
The index of data row begin from 0, however the index of label row begin from -1, number from the bottom up, -1, -2, -3 and so on. The code below shows how to get label type from the row index. Then get label contents by label type according to the above section.
Worksheet wks;
wks = Project.ActiveLayer();
int nRowIndex = -1; // the last header row
int nLabelType = wks.GetLabelType(nRowIndex);
// 1 means the row is user defined label, else 0 means not
out_int("", nLabelType == RCLT_UDL);
Get Label Contents by Label Name
If want to get user defined label contents by label name, need to find the label by label name firstly. Then use Grid::GetLabelsByType method to get label contents by label type.
There are two ways to find the user defined label, please choise one based on Origin version.
Minimum Origin Version Required: Origin 8.5 Sr1
Worksheet wks = Project.ActiveLayer();
// find the label named Threshold
int nLabelType = find_user_defined_label(wks, "Threshold");
out_int("Label Type=", nLabelType);
Minimum Origin Version Required: Origin 8.1 Sr0
#include <Dialog.h>
#define IDC_WORKSHEET 1001
void Worksheet_Get_Label_Contents_ex(Dialog& dlg)
{
Worksheet wks = Project.ActiveLayer();
Grid gg;
gg.Attach(wks);
vector<string> vsLabelNames;
if( gg.GetUserDefinedLabelNames(vsLabelNames) )
{
string strLabelName = "Threshold"; // input
// return -1 means not found, else return the index in vector
int nn = vsLabelNames.Find(strLabelName);
out_int("", nn);
int nLabelType;
if( nn >= 0 )
nLabelType = RCLT_UDL + nn;
out_int("Label Type=", nLabelType);
}
}
After get label type index by label name, see the above section to get row label contents by label type index.
|