title: Elegant way of exporting data from IEnumerable object to an Excel datasheet in c#?
body: <p>My data is held in an IEnumerable object and I want that to be populated into a table in excel. </p>
  
  <p>Basically I am able to export data to the Excel sheet but I dont know export a table in a more elegant way. </p>
  
  <p>This is what I have:</p>
  
  <pre><code> //Populate column names
   String[] columnNames = {"val1", "val2", "val3", "val4", "val5"};
   for (int p = 1, l = 1; l &lt;= 5;l++)
   {
             xlWorkSheet.Cells[p, l] = columnNames[l-1]; 
   }
  
   //Entries is an IEnumerable object
   int i = 1;
   foreach (var e in Entries)
   {
              int j = 1;
              xlWorkSheet.Cells[i, j] = e.val1; j++;
              xlWorkSheet.Cells[i, j] = e.val2; j++;
              xlWorkSheet.Cells[i, j] = e.val3; j++;
              xlWorkSheet.Cells[i, j] = e.val4; j++;
              xlWorkSheet.Cells[i, j] = e.val5; j++; 
              i++; 
    }
  </code></pre>
  
  <p>I was thinking about converting the data from IEnumerable to datatable like this <a href="https://stackoverflow.com/questions/1253725/convert-ienumerable-to-datatable">Convert IEnumerable to DataTable</a> but i thought it will introduce an extra layer of unnecessary complexity. </p>
  
  <p>What are your thoughts? </p>
  
  <p>Thanks</p>