3.12.4.1 List Worksheets and Columns in Workbook
Version Info
Minimum Origin Version Required: Origin 8 SR0
List Worksheets and Columns in Workbook dynamically
In the active worksheet page, list all the worksheets in the listbox,
After selecting the workswheet, all the columns of the selected worksheet will list in the second listbox.
Example
#include <GetNbox.h>
void Get_worksheet_column()
{
GETN_BOX(trRoot) // construct a GetN_Box name "trRoot"
// list box
GETN_LIST(wks, "Worksheet", 0, "A")
// list box
GETN_LIST(col, "Column", 0, "B")
if( GetNBox(trRoot, node_event, "Example", NULL, GetWindow()) )
return;
}
int node_event(TreeNode& trRoot, int nRow, int nEvent, DWORD& dwEnables,
LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux,
string& strErrMsg)
{
if( GETNE_ON_INIT == nEvent )
{
WorksheetPage pg = Project.Pages(); //Get the active page
if ( !pg ) //Check if the worksheet page exists
return 0;
vector<string> saNames;
foreach(Layer ly in pg.Layers)
{
string strName;
ly.GetName(strName); //Get worksheet name
saNames.Add(strName); //Add worksheet name to string array
}
string str;
str.SetTokens(saNames, '|'); //Copy a string array to a str
trRoot.wks.SetAttribute(STR_COMBO_ATTRIB, str);//Show worksheet name in the listbox
}
if( GETNE_ON_INIT == nEvent || 0 == lstrcmp(lpcszNodeName, "wks") )
{
WorksheetPage pg = Project.Pages(); //Get the active page
if ( !pg )
return 0;
Worksheet wks = pg.Layers(trRoot.wks.nVal);
vector<string> saNamescol;
foreach(Column cc in wks.Columns)
{
string strNamecol, strDesig;
strNamecol = cc.GetLongName(); //Get columnn longname
if ( strNamecol.IsEmpty() )
cc.GetName(strNamecol);
int nType = cc.GetType(); //Get columns designations
switch ( nType )
{
case OKDATAOBJ_DESIGNATION_X:
strDesig = 'X';
break;
case OKDATAOBJ_DESIGNATION_Y:
strDesig = 'Y';
break;
case OKDATAOBJ_DESIGNATION_Z:
strDesig = 'Z';
break;
case OKDATAOBJ_DESIGNATION_NONE:
strDesig = "None";
break;
case OKDATAOBJ_DESIGNATION_ERROR:
strDesig = "YErr";
break;
case OKDATAOBJ_DESIGNATION_L:
strDesig = 'L';
break;
case OKDATAOBJ_DESIGNATION_X_ERROR:
strDesig = "XErr";
break;
}
saNamescol.Add(strNamecol + " (" + strDesig + ")");
}
string str2;
str2.SetTokens(saNamescol, '|');
trRoot.col.SetAttribute(STR_COMBO_ATTRIB, str2);
}
return 0;
}
|