Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi..

i have an aspx page...how to download this page in excel format??
Posted
Comments
joginder-banger 17-Dec-13 6:38am    
What's you try. plz clear what's you want.
JoCodes 17-Dec-13 6:40am    
What you tried so far?What you want to download?Are you looking for an export to pdf functionality from any data control?

Okay what you are referring to is called as export to excel functionality.
What you have to do is you have to simply bind the data to your gridview and display it then you can create a button on which you will write the functionality for export to excel.

For e.g
VB
<asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel from Gridview" OnClick="btnExportToExcel_Click"
           />



And your function would be something like this thats all you have to do nothing more than that:

protected void btnExportToExcel_Click(object sender, EventArgs e)
        {
            string attachment = "attachment; filename=Emp.xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridViewExport.RenderControl(htw);  // Your gridview Id.
            Response.Write(sw.ToString());
            Response.End();
        }
 
Share this answer
 
Comments
Member 10276220 17-Dec-13 8:26am    
hi Shahid Bhat...thanx for your help....i have to convert some paragraph & table also...how to do this???
Do you have to download the page or data in a gridview control, Please clarify.
 
Share this answer
 
Comments
Member 10276220 17-Dec-13 6:40am    
i have a aspx page...now i want to download this page in excel format on a button click...how to do this???
Member 10276220 17-Dec-13 6:51am    
i have to download table & gridview control
JoCodes 17-Dec-13 9:15am    
Dont add comments as solution.

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