title: How to find specific in a cell that is next to the search string in excel file by c#?
body: <p>I'd like to ask if anyone would know how to solve my problem. Trying to find a string in an excel file but I need to extract the value next in the cell and the value write in to the text file.
  My individual steps:</p>
  <ol>
  <li>Open Excel file</li>
  <li>Find the cells</li>
  <li>Create new text file</li>
  <li>Write my value from xlxs file</li>
  </ol>
  <p>It looks easy but I'm too stupid to create it :D</p>
  <p>Form1:</p>
  <pre><code>using System;
  using System.IO;
  using System.Windows.Forms;
  
  
  namespace WindowsFormsApp2
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          OpenFile();
      }
  
      public void OpenFile()
      {
          Class1 excel = new Class1(@&quot;C:\Users\info\Documents\Zkouska.xlsx&quot;,1) ;
          string path = @&quot;C:\Users\info\Documents\new.txt&quot;;
          TextWriter tw = new StreamWriter(path, true);
  
         tw.Write(excel.ReadCell(0, 0));
      }
  }
  }
  </code></pre>
  <p>Class1:</p>
  <pre><code>using Microsoft.Office.Interop.Excel;
  using System;
  using _Excel = Microsoft.Office.Interop.Excel;
  
     namespace WindowsFormsApp2
  {
  class Class1
  {
      string path = &quot;&quot;;
      _Application excel = new _Excel.Application();
      Workbook wb;
      Worksheet ws;
  
      public Class1(string path, int Sheet)
      {
          this.path = path;
          wb = excel.Workbooks.Open(path);
          ws = (Worksheet)wb.Worksheets[Sheet];
      }
      public string ReadCell(int i, int j)
      {
          i++;
          j++;
          string cellvalue = ws.Cells[i, j].Value2 as String; 
          if (cellvalue == &quot;Z_KomSilnice_L (24200)/7 &quot;)
          {
              return ws.Cells[i, j++];
          }
          else
              return &quot;&quot;;
          }
  } 
  }
  </code></pre>
  <p>If I try to run it will show the error:</p>
  <p>Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Operator '==' cannot be applied to operands of type 'System.__ComObject' and 'string''
  in line:</p>
  <pre><code>string cellvalue = ws.Cells[i, j].Value2 as String;
  </code></pre>
  <p>Can I use to Contains(string)?</p>
  <p>Perhaps I've described it enough, I'm new here so please be patient :)</p>
  <p>Thank you so much for your advice :)</p>