I have often feel the need for developers to generate an Excel report requirement. Here is a small code snippet to produce the same.
string path = Path.GetTempFileName();
StreamWriter writer = new StreamWriter(path);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
Response.ContentType = “application/x-msexcel”;
DataGrid grid = new DataGrid();
grid.DataSource = data; //data to be written in the excel file
Hope it helps.