Grid View To Excel
Posted
by rahulchandran
on Stack Overflow
See other posts from Stack Overflow
or by rahulchandran
Published on 2009-07-07T00:14:57Z
Indexed on
2010/05/21
15:00 UTC
Read the original article
Hit count: 300
ASP.NET
Hi I am trying to convert the contents of a grid View to an excel file and I am doing it using this code
string attachment = "attachment; filename= " + FileName;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
The problem is I am getting some sort of html in an excel style format , theres java script in the page links etc what I want is to turn the results of my query into a comma seperated file Is that do-able for free or do I have to run the query myself get the data and write out a csv stream Thanks
© Stack Overflow or respective owner