title: How do I export a C# object list to an excel spreadsheet?
body: <p>I have a C# list that I created from an Excel spreadsheet, and I want to export it to Excel. How can I achieve that task? This is just a console project. I do not intend to display the data in a .Net application. I just need the spread sheet.</p>
  
  <pre><code>var fileName = string.Format("C:\\Users\\SGurmu\\Desktop\\Data 091510.xls");
  var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
  
  var fileName2 = string.Format("C:\\Users\\SGurmu\\Desktop\\Copy of Prototype.xls");
  var connectionString2 = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
  
  var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
  var ds = new DataSet();
  
  adapter.Fill(ds, "contacts");
  
  var data = ds.Tables["contacts"].AsEnumerable();
  
  List&lt;EmployeeData&gt; query = data.Where(x =&gt; x.Field&lt;string&gt;("First_Name") != string.Empty).Select(x =&gt;
  
  new EmployeeData
      {
      empID = x.Field&lt;double&gt;("EMPLOYEE"),
      firstName = x.Field&lt;string&gt;("First_Name"),
      lastName = x.Field&lt;string&gt;("Last_Name"),
      JobCategory = x.Field&lt;string&gt;("Job Title"),
      StartDate = x.Field&lt;Nullable&lt;DateTime&gt;&gt;("Hire Dt"),
      EndDate =   x.Field&lt;Nullable&lt;DateTime&gt;&gt;("Term Dt"),
      TermReason = x.Field&lt;string&gt;("Term Reason"),
      PeggedUID = x.Field&lt;Nullable&lt;double&gt;&gt;("Pegged UserID"),
      UpdateDate = x.Field&lt;Nullable&lt;DateTime&gt;&gt;("Last Updated")
      }).ToList();
  </code></pre>