Once you have the results in to a table, just bind the table to a temporary datagrid and use the datagrid/gridview rendercontrol method.. as shown in the code below.
before rendering the html to the response, you need to do the following,
1. Clear the response headers
2. Clear the response content
3. Set the charset of the response to empty
4. Set the MIME type by setting the Reponse.ContentType property..to "application/vnd.ms-excel"
dgReport.DataSource = Tableview;
dgUserSummary.DataBind();
Response.ClearHeaders();
Response.ClearContent();
Response.Charset = "";
// Turn off the view state.
this.EnableViewState = false;
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlTextWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
//Get the html for the datagrid, which has the userdetails
dgReport.RenderControl(htmlTextWriter);
// Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Report.cvs");
Response.Write(stringWriter.ToString());
Response.End();