Threshold or matching string replacement for a DataRange.
BOOL Replace( double dThresholdVal, double dReplaceVal, uint wBitwiseOptions = WKSREPL_TEST_EQUAL, int nIndex = 0, double rTolerance = 1e-8, BOOL bUndo = FALSE )
BOOL Replace( LPCSTR strOld, LPCSTR strNew, uint wBitwiseOptions = WKSREPL_TEST_STR_MATCH_WHOLE_WORD, int nIndex = 0, BOOL bUndo = FALSE )
Returns TRUE if successful else return FALSE
Returns TRUE if successful else return FALSE
EX1
//Replace the data<=50 in the worksheet with 50. void DataRange_Replace_Ex1(int nCol1 = 0, int nCol2 = 1) { //Creat a worksheet with two columns and fill with data. Worksheet wks ; wks.Create(); if( wks ) { while(wks.Columns(0)) wks.DeleteCol(0); wks.AddCol("A"); wks.AddCol("B"); double rr; for(int j=0;j<2;j++) { for (int i=0;i<10;i++) { rr=rnd(); wks.SetCell(i,j,rr*100); } } //Create a datarange with X and Y subranges. DataRange dr; dr.Add("X", wks, 0, nCol1, -1, nCol1); dr.Add("Y", wks, 0, nCol2, -1, nCol2); int nNumRanges = dr.GetNumRanges(); uint wBitwiseOptions = WKSREPL_TEST_LESSTHAN | WKSREPL_TEST_EQUAL; for(int ii = 0; ii < nNumRanges; ii++) dr.Replace(50, 50, wBitwiseOptions, ii);//replace the data value <= 50 with 50. } }
EX2
//Add ".cn" in the end of each sample string. void DataRange_Replace_Ex2(int nCol1 = 0) { //Create a worksheet and fill with strings. Worksheet wks; wks.Create(); if(wks) { //Create sample data. wks.SetCell(0, 0, "angel@originlab.com"); wks.SetCell(1, 0, "amy@originlab.com"); wks.SetCell(2, 0, "betty@originlab.com"); wks.SetCell(3, 0, "carol@originlab.com"); //Create a datarange with two subranges. DataRange dr; dr.Add("Range1", wks, 0, nCol1, -1, nCol1); //Match the whole string. uint nOptions = WKSREPL_TEST_STR_MATCH_WHOLE_WORD; Column col(wks, 0); int nNumRows = col.GetNumRows(); string strText; for(int ii = 0; ii < nNumRows; ii++) { wks.GetCell(ii, 0, strText); dr.Replace(strText, strText+".cn", nOptions, 0); //Add ".cn" in the end of the string. } } }
origin.h