fantasylan
asked on
How to save the contents of a GridView to an excel spreadsheet
I am trying to save my GridView data as an Excel file.
Here's my code
Response.Clear();
Response.AddHeader("conten t-disposit ion", "attachment;filename=Repor t.xls");
// Response.ContentType = "application/octet-stream" ;
// If you want the option to open the Excel file without saving then
// comment out the line below
//Response.Cache.SetCachea bility(Htt pCacheabil ity.NoCach e);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit er htmlWrite = new HtmlTextWriter(stringWrite );
GridView3.RenderControl(ht mlWrite);
Response.Write(stringWrite .ToString( ));
Response.End();
It doesn't work and I get a I get an error about Managed Pipelines. After changing it to Integrated, I still cant get it to work.
Regards.
Here's my code
Response.Clear();
Response.AddHeader("conten
// Response.ContentType = "application/octet-stream"
// If you want the option to open the Excel file without saving then
// comment out the line below
//Response.Cache.SetCachea
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit
GridView3.RenderControl(ht
Response.Write(stringWrite
Response.End();
It doesn't work and I get a I get an error about Managed Pipelines. After changing it to Integrated, I still cant get it to work.
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.