Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to export from gridview to excel sheet.
I have added code like that:

try
        {
            System.Web.UI.WebControls.Repeater gvSource = (System.Web.UI.WebControls.Repeater)Source;
            string attachment = "attachment; filename=" + strFileName.Trim().ToUpper() + ".xls";
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", attachment);
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
            //   htw.WriteLine("<H1>" + lblHeader.Text.ToString() + ddlAccounts.Text.ToString()+ "<H1>");
            gvSource.RenderControl(htw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();
        }
        catch (Exception Ex)
        {
        }




In excel we have property to set Header and footer. Can we have same facility in C#.net to set header and footer for excel export?
Posted
Updated 3-Sep-10 3:21am
v2
Comments
Dalek Dave 3-Sep-10 9:21am    
Edited for Grammar and Code Block.

1 solution

excel supper XML format ,you let DataTable Output XML then change extention name to xls
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900