Export to Excel (Windows forms only)
This is basically the easiest way to export data from a
DataSet to Excel.
I looked all over the Internet and could not find anything useful, only ASP.NET ways of exporting. You just need to add to Excel DLL your references. I have looked over the Internet for the easiest way of doing it and at the end ended up doing this. Just put the code where ever you want to call the event that export the
DataGrid to Excel.
Excel.ApplicationClass excel = new ApplicationClass();
DataTable table = DATASETNAME.Tables;
foreach(Datacolumn col in table.Columns)
foreach(DataRow row in table.Row)
foreach(DataColumn col in table.Columns)
excel.Visible = true;
Worksheet worksheet = (Worksheet)excel.ActiveSheet;
I know its not the most difficult thing on the planet to make, but it can be useful to beginners.