Extracts a Worksheet to a new or an existing worksheet
BOOL Extract( Worksheet & wksDest, const vector<uint> & vnRowIndices, const vector<uint> & vnColIndices )
TRUE if succesful FALSE otherwise
EX1
//Extract a worksheet data to another worksheet. void Worksheet_Extract_Ex1() { Worksheet wks("Book1"); Worksheet wksDest("Book2"); vector<uint> vnRowIndices = {0,1,4,6}; vector<uint> vnCols = {1,3}; BOOL bRet = wks.Extract(wksDest, vnRowIndices, vnCols); if(bRet) out_str("done"); }
EX2
// example to show how to extract data from a worksheet and put it back to the same // worksheet. // We will use col(2) alias as 'a' to test for missing values // we first define the NULL const as 0/0 and then // we setup alias a as col(2) // You need to setup a worksheet with 5 columns and put some cells in col(2) // as missing, like put in text and those are the rows we will extract void Worksheet_Extract_Ex2() { string strCond = "a==null"; string strLTRunBeforeloop = "const null=0/0;range a=2"; Worksheet wks = Project.ActiveLayer(); vector<uint> vnRowIndices; // assume the active wks has at least 5 columns vector<uint> vnCols = {0,2,3,4}; int nn = wks.SelectRows(strCond, vnRowIndices, 0, -1, -1, strLTRunBeforeloop); if(nn < 0) out_str("User cancel"); else if(nn == 0) out_str("no matching row"); else { Worksheet wksTemp; if(wksTemp.CreateCopy(wks, CREATE_HIDDEN, DCTRL_COPY_DATA)) { BOOL bRet = wksTemp.Extract(wks, vnRowIndices, vnCols); if(bRet) out_str("done"); } wksTemp.Destroy(); } }
origin.h