Select rows from worksheet based on a LabTalk condition expression
int SelectRows( LPCSTR lpcszCondition, vector<uint> & vnRowIndices, int r1 = 0, int r2 = -1, int nMax = -1, LPCSTR lpcszBeforeLoopScript = NULL, LPCSTR lpcszBeforeIfScript = NULL, LPCSTR lpcszAfterIfScript = NULL, DWORD dwCntrl = 0, LPCSTR lpcszAfterLoopScript = NULL )
number of rows (size of vnRowIndices) if success, otherwise returns
-1 if lpcszCondition has syntax error
-2 if lpcszBeforeScript has syntax error
EX1
// example to test col(2) alias as a for missing values // we first define the NULL const as 0/0 and then // we setup alias a as col(2) void Worksheet_SelectRows_Ex1(string strCond = "a==null", string strPre = "const null=0/0;range a=2") { Worksheet wks("Book1"); Worksheet wksDest("Book2"); vector<uint> vnRowIndices; vector<uint> vnCols = {0,2}; int nn = wks.SelectRows(strCond, vnRowIndices, 0, -1, -1, strPre); if(nn < 0) out_str("User cancel"); else if(nn == 0) out_str("no matching row"); else { BOOL bRet = wks.Extract(wksDest, vnRowIndices, vnCols); if(bRet) out_str("done"); } }
EX2
// example on how to select cells by matching text // wildcard support is automatic if either * or ? characters are found in the // testing string. // // To try, put data into a sheet with some text in col(2) // this function can allow you to select rows by a string // like // Worksheet_SelectRows_Ex2 "my string" // Worksheet_SelectRows_Ex2 *Boston* void Worksheet_SelectRows_Ex2(string strCell = "*about*") { string strPre = "range b=2"; string strCond = "b=="; strCond += "\"" + strCell + "\""; Worksheet wks = Project.ActiveLayer(); vector<uint> vnRowIndices; int nn = wks.SelectRows(strCond, vnRowIndices, 0, -1, -1, strPre); Grid gg; if(gg.Attach(wks)) { vector<int> vnRows; vnRows = vnRowIndices; if(nn) gg.SetSelection(vnRows); else gg.SetSelection(NULL); out_int("Number of rows =", nn); } }
Worksheet::Extract, Grid::SetSelection, Worksheet::SetSelectedRange
origin.h