Use the code below,
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
ConvertXL(Response);
}
public void ConvertXL(HttpResponse Response)
{
try
{
gvdetails.SelectedIndex = -1;
Response.Clear();
HtmlForm form = new HtmlForm();
string attachment = "attachment;filename=UserLogDetails.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.xls";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(gvdetails);
this.Controls.Add(form);
form.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
}
catch (Exception ex)
{
return;
}
}
And for export to Word use
Response.ContentType = "application/ms-word";