I've used the following function for Excel export.
private void ExporttoExcel(DataTable table)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Write(@");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Reports.xls");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
//sets font
HttpContext.Current.Response.Write("<font style="font-size:10.0pt; font-family:Calibri;">");
HttpContext.Current.Response.Write("<br><br><br>");
//sets the table border, cell spacing, border color, font of the text, background, foreground, font height
HttpContext.Current.Response.Write("<table border="1" bgcolor="#ffffff" hold=" /> " bordercolor="#000000" cellspacing="0" cellpadding="0" style="font-size:10.0pt; font-family:Calibri; background:white;"> <tr>");
////am getting my grid's column headers
//int columnscount = g .Columns.Count;
//for (int j = 0; j < columnscount; j++)
//{ //write in new column
// HttpContext.Current.Response.Write("<td>");
// //Get column headers and make it as bold in excel columns
// HttpContext.Current.Response.Write("");
// HttpContext.Current.Response.Write(GridView_Result.Columns[j].HeaderText.ToString());
// HttpContext.Current.Response.Write("");
// HttpContext.Current.Response.Write("</td>");
//}
HttpContext.Current.Response.Write("</tr>");
foreach (DataRow row in table.Rows)
{//write in new row
HttpContext.Current.Response.Write("<tr>");
HttpContext.Current.Response.Write("<td>");
HttpContext.Current.Response.Write(row[0].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("<td style="width: 2.5px;">");
HttpContext.Current.Response.Write(row[1].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("<td>");
HttpContext.Current.Response.Write(row[2].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("<td style="width: 2.5px;">");
HttpContext.Current.Response.Write(row[3].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("<td>");
HttpContext.Current.Response.Write(row[4].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("<td>");
HttpContext.Current.Response.Write(row[5].ToString());
HttpContext.Current.Response.Write("</td>");
HttpContext.Current.Response.Write("</tr>");
}
HttpContext.Current.Response.Write("</table>");
HttpContext.Current.Response.Write("</br></br></br></font>");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}