title: How do I search for specific text in an Excel worksheet and get the address that the text is occupying using C#?
body: <p>I am writing a program that will allow me to open excel spreadsheets and get some specific information off of them. Each sheet contains the same information that I need, but the information is not always in the same location.</p>
  
  <p>I am trying to find a way to search for specific text in an Excel sheet and have the address of the cell that text is in.</p>
  
  <p>For example:
  If I was looking for the text "apples", the function will find the cell that contains apples and return its address (i.e., A5).</p>
  
  <p>For accessing the Excel spreadsheet I am using Excel = Microsoft.Office.Interop.Excel.
  I have been looking all weekend for an efficient way to to do this and have been horribly unsuccessful so far. Any help I can get would be greatly appreciated.</p>
  
  <p>Edit:
  This is part of a much larger project, but for this particular function, I have the ability to open and close the Excel file. I have yet to start writing the search function yet, because to be perfectly honest, I am not exactly sure on even how to go about doing this. But here is what I have at this point.</p>
  
  <pre><code>public string searchExcel(string findThis)
  {
      Excel.Application xlApp;
      Excel.Workbook xlWorkBook;
      Excel.WorkSheet xlWorkSheet;
      object misvalue;
  
      //This part will open the Excel document.
      misValue = System.Reflection.Missing.Value;
      xlApp = new Excel.ApplicationClass();
      xlWorkBook = xlApp.Workbooks.Open("C:\\temp2\\excelDocument.xlsm", 
      0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, 
      "\t", false, false, 0, true, 1, 0);
  
  
      //Search and get address of cell
  
  
      //This part will close the Excel document
      xlWorkBook.Close(true, misValue, misvalue);
      xlApp.Quit();
  
      releaseObject(xlWorkSheet);
      releaseObject(xlWorkBook);
      releaseObject(xlApp);
  
      xlWorkSheet = null;
      xlWorkBook = null;
      xlApp = null;
  }
  
  private void releaseObject(object obj)
  {
      try
      {
          System.Runtime.Interopservices.Marshal.ReleaseComObject(obj);
          obj = null;
      }
      catch(Exception e)
      {
          obj = null;
          MessageBox.Show("Unable to release the object " + e.ToString());
      }
      finally
      {
          GC.Collect();
      }
  }
  </code></pre>