I've use FindString() to find a word in the worksheet. My problem is that the word occurs more than once in the worksheet. FindString() only return a single cell, is it possible to return an array of cells if there is more than 1 occurences?
try { Worksheet worksheet = workbook.Worksheets[0]; Cells cells = worksheet.Cells; ArrayList al = new ArrayList(); Cell foundcell; Cell prevcell = null; int i = 0; string datatosearch = "DATA";
do {
foundcell = cells.FindString(datatosearch,prevcell); //when no data found exit the loop. if (foundcell == null) break; al.Add((string)foundcell.Name); prevcell = foundcell;
}while(foundcell!= null);
//Convert the arraylist to string array, //the array contains cell names. string []scells =(string[]) al.ToArray(typeof(string)); MessageBox.Show("Total Cells found : " + scells.Length);
//Scan the array to fetch the cell names. for (int a=0;a<scells.Length;a++) { MessageBox.Show(scells[a]);