Q:

How to exporting data from a List to excel file?

I have a List<Person> which is bound to a grid view.
I want to export all the values to an excel file.
My person class is as follows:
class Person
{
    public string Name { get; set; }
    public string City { get; set; }
    public int Age { get; set; }
}

Is there any way to do it?
Please suggest....

A:

you will need an SDK to save as the xlsx format. I dont know where to get the openxml sdk to do it, but here is a code snippet to save as a CSV which can be opened in excel as well.
List<Person> persons; // populated earlier
using(StreamWriter wr = new StreamWriter("myfile.csv"))
{
   foreach(Person person in persons)
   {
     wr.WriteLine(person.Name + "," + person.City + "," + person.Age);
   }
}

