title: how to get data in a row column format from an excel file in c#.net
body: <p>I have an excel sheet which contains data, in table like form, which first line is column names and rest are all rows. I want to insert data into a table in database. I have done everything to insert data to database except for getting data from excel sheet. I have tried following code but it gave data in sequential way no descrimination between rows and columns. But i want data like (columnname,rowdata)</p>
  
  <p>This is data in excel file</p>
  
  <pre><code>firstname  lastname  salary  age
  sasi   kiran    88000   32
  ravi   kiran    92000   23
  jafer  sharif   34000   45
  kiran  bedi     45000   34
  </code></pre>
  
  <p>following code i have tried:</p>
  
  <pre><code>Excel.Application xlApp;
      Excel.Workbook xlWorkBook;
      Excel.Worksheet xlWorkSheet;
      Excel.Range range;
      string str;
      int rCnt = 0;
      int cCnt = 0;
      xlApp = new Excel.Application();
      xlWorkBook = xlApp.Workbooks.Open(@"D:\Copy of Macro with Radio_Test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
      xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
      range = xlWorkSheet.UsedRange;
  
      for (rCnt = 1; rCnt &lt;= range.Rows.Count; rCnt++)
      {
          for (cCnt = 1; cCnt &lt;= range.Columns.Count; cCnt++)
          {
              str = (Convert.ToString((range.Cells[rCnt, cCnt] as Excel.Range).Value2));
              Console.WriteLine(str);
              Console.ReadLine();
          }
      }
  </code></pre>
  
  <p>but here i should get value like</p>
  
  <pre><code>console.writeline(firstname, sasi);
  console.writeline(lastname, kiran);
  </code></pre>
  
  <p>etc for all values
  how to modify the code to achieve the result</p>