About
Pricing
Community
Teams
Start Free Trial
Log in
searchsanjaysharma
asked on
12/29/2012
This code of export to excel saves the whole page with extension .aspx
How to correct this .xls or .xlsx
private void ExportToExcel(string strFileName, GridView dg)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel"
;
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit
er oHtmlTextWriter = new System.Web.UI.HtmlTextWrit
er(oString
Writer);
GridView1.RenderControl(oH
tmlTextWri
ter);
Response.Write(oStringWrit
er.ToStrin
g());
Response.End();
}
C#
ASP.NET
6
1
Last Comment
searchsanjaysharma
8/22/2022 - Mon
AndyAinscow
12/29/2012
>>This code of export to excel saves the whole page with extension .aspx
>>How to correct this .xls or .xlsx
Hmmmmm. Telling us what the problem is would help.
AndyAinscow
12/29/2012
ps. If you wanted an xls file then is writing to a
HTMLTextWriter
a good idea?
searchsanjaysharma
12/29/2012
ASKER
The problem is i want .xls extension, so that whenever anyone clicks on downloaded file, it opens in excel.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
sognoct
12/29/2012
use this script instead :
http://forums.asp.net/t/1542176.aspx/1
ASKER CERTIFIED SOLUTION
Rouchie
12/29/2012
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
searchsanjaysharma
1/16/2013
ASKER
tx
>>How to correct this .xls or .xlsx
Hmmmmm. Telling us what the problem is would help.