int FindNext(Datasheet& ds, int& nCol, int& nRow, double dThresholdVal, uint wBitwiseOptions = WKSREPL_TEST_EQUAL, int nIndex = -1, double rTolerance = 1e-8, double* pdReplaceVal = NULL, BOOL bUndo = FALSE, int* pnMatrixObjectIndex = NULL)
int FindNext(Worksheet& wks, int& nCol, int& nRow, LPCSTR lpcszOld, uint wBitwiseOptions = WKSREPL_TEST_STR_MATCH_WHOLE_WORD, int nIndex = -1, LPCSTR lpcszNew = NULL, BOOL bUndo = FALSE)
Bitwise Options:
Returns an integer with one or more of the following bits set:
DATARANGE_FIND_NEXT_SUCCESSFULLY_FOUND = 0x00010000 DATARANGE_FIND_NEXT_INPUT_MATCHED_CONDITIONS = 0x00020000 DATARANGE_FIND_NEXT_SUCCESSFULLY_REPLACE_INPUT = 0x00040000 DATARANGE_FIND_NEXT_INVALID_ARGUMENT = 0x00000001
These constants are declared in OC_const.h
EX1
//Find a cell in worksheet which is equal or less than 50.0 according to the datarange index. void DataRange_FindNext_Ex1() { Worksheet wks; wks.Create(); if (wks) { while (wks.Columns(0)) wks.DeleteCol(0); wks.AddCol("A"); wks.AddCol("B"); for (int j = 0; j < 2; j++) for (int i = 0; i < 2; i++) wks.SetCell(i, j, rnd() * 100); DataRange dr; dr.Add("Range1", wks, 0, 0, -1, 0); // from row,col, to row,col dr.Add("Range2", wks, 0, 1, -1, 1); // from row,col, to row,col int nCol, nRow; uint nOptions = WKSREPL_TEST_LESSTHAN|WKSREPL_TEST_EQUAL; int nRangeIndex = 1;//Find in the Range1. int nRet = dr.FindNext(wks, nCol, nRow, 50.0, nOptions, nRangeIndex); printf("FindNext returned %d\n", nRet); printf("nCol == %d, nRow == %d\n", nCol, nRow); } }
EX2
//Find a cell in worksheet which is whole match the string "Abc" with case-sensitive according to the datarange index. void DataRange_FindNext_Ex2() { Worksheet wks; wks.Create(); if(wks) { wks.SetCell(0,0,"ab"); wks.SetCell(1,0,"Ab"); wks.SetCell(2,0,"abc"); wks.SetCell(3,0,"Abc"); DataRange dr; dr.Add(wks,0,"Range"); int nCol, nRow; uint nOptions =WKSREPL_TEST_STR_CASE_SENSITIVE;//Match the string with case-sensitive. int nRangeIndex = 0; int nRet = dr.FindNext(wks, nCol, nRow, "Abc", nOptions, nRangeIndex); printf("FindNext returned %d\n", nRet); printf("nCol == %d, nRow == %d\n", nCol, nRow); } }
EX3
//wildchar search column for string and dump the row index void col_find_rows(int nCol, string StrToFind) { Worksheet wks = Project.ActiveLayer(); nCol--;//OC index from 0, LT from 1 if(nCol < 0 || nCol > wks.GetNumCols()-1) { out_int("invalid col index: ", nCol+1); return; } char szBookSName[100]; LT_get_str("%H", szBookSName, 100);//active book from %H string strBookRange; strBookRange.Format("[%s]",szBookSName); DataRange dr;//need a Book datarange to search a sheet at specified column dr.Create(strBookRange); int nRow = DATARANGE_FIND_REPLACE_INVALID_ROW_INDEX; int ii = 1; while(true) { int nRet = dr.FindNext(wks, nCol, nRow, StrToFind, WKSREPL_TEST_STR_WILDCARD_MATCHING); if(!( nRet & DATARANGE_FIND_NEXT_SUCCESSFULLY_FOUND)) break;//not found printf("%d: found at col %d row %d\n", ii++, nCol+1, nRow+1); if(ii > 10) // testing code, don't show too many break; } } void DataRange_FindNext_Ex3() { Worksheet wks; wks.Create("origin"); vector<string> vs1 = {"ABCD", "d", "abcd", "f", "qqabc", "ab"}; vector<string> vs2 = {"q", "qqabc", "e", "r", "t", "abcd"}; wks.Columns(0).PutStringArray(vs1); wks.Columns(1).PutStringArray(vs2); col_find_rows(2, "*abc*"); }
origin.h