Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i'm using the below code toexport the gridview to Excel,i got code from net..so any one pls let me knw the process of the code.....
Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition","attachment;filename=g.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter ht = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(ht);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
Posted 8-Mar-11 1:52am
Comments
shanthikalai at 8-Mar-11 6:53am
   
and also y we use render in above code
Amit Kumar Tiwari at 8-Mar-11 7:27am
   
RenderControl outputs server control content and stores tracing information about the control if tracing is enabled.
sjelen at 4-May-12 13:15pm
   
This is not real export to excel - you are making a html file with .xls extension and rely on Excel to convert it for you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi
refer this one
 
Export grid view to excel[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
Use following code
 
Response.Clear(); 
Response.Charset = ""; 
Response.ContentType = "application/vnd.ms-excel"; 
Response.AppendHeader("content-disposition", "attachment; filename=ExportData.xls");
System.IO.StringWriter sw = new System.IO.StringWriter(); 
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw); 
GridView gv = new GridView();
gv.DataSource = dataTable; 
gv.DataBind();
gv.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
  Permalink  
Comments
Suraj S Koneri at 27-Jun-12 5:09am
   
Thanks it helped to solve my problem :)
Omkar Joshi at 23-Jul-13 10:09am
   
where we get xls sheet which was exported
from grid?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

this[^] might help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Check this tutorial:
Export gridview or repeater data to excel with custom results and styles
http://www.magic-dev.com/export-to-excel.htm[^]
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 4 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100