title: How to get user input Excel sheet and generate output.xls file in C# windows firm?
body: <p>My goal is to create a simple (one file) executable for windows environment that will open a pretty simple form. The form will read data from with two different Excel files and submit it - the application will write the data in to output.xls Excel file.</p>
  
  <p>I have posted my sample sheet in below link for your ref:</p>
  
  <p><a href="http://server.myspace-shack.com/d21/makk.jpg" rel="nofollow">Please click this link</a></p>
  
  <ol>
  <li><p>To check whether the date is available for column C "120" from sheet1 to sheet2 based on vlookup function in excel</p></li>
  <li><p>if it is not available date in sheet2 then create output for "120"</p></li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>namespace WindowsFormsApplication2
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              OpenFileDialog openFD = new OpenFileDialog();
              //openFD.Filter = "Excel(*.xlx; *.xlsm; *.gif; *.bmp)";
  
              if (openFD.ShowDialog() == DialogResult.OK)
              {
                  textBox1.Text = openFD.FileName;
              }
  
         }
  
          private void button3_Click(object sender, EventArgs e)
          {
  
              OpenFileDialog openFD = new OpenFileDialog();
              //openFD.Filter = "Excel(*.xlx; *.xlsm; *.gif; *.bmp)";
  
              if (openFD.ShowDialog() == DialogResult.OK)
              {
                  textBox2.Text = openFD.FileName;
              }
  
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
  
              using (OleDbConnection conn = new OleDbConnection())
              {
                  DataTable dt = new DataTable();
                  string Import_FileName = path;
                  string fileExtension = Path.GetExtension(Import_FileName);
                  if (fileExtension == ".xls")
                      conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Import_FileName + ";" + "Extended Properties='Excel 8.0;HDR=YES;'";
                  if (fileExtension == ".xlsx")
                      conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Import_FileName + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'";
                  using (OleDbCommand comm = new OleDbCommand())
                  {
                      comm.CommandText = "Select * from [" + sheet1 + "$]";
  
                      comm.Connection = conn;
  
                      using (OleDbDataAdapter da = new OleDbDataAdapter())
                      {
                          da.SelectCommand = comm;
                          da.Fill(dt);
                          return dt;
                      }
  
                  }
              }
  
  
          }
      }
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>please guide me to do this task.</p>