protected void Page_Load(object sender, EventArgs e)
{
//SqlDataSource1.SelectCommand="select companyName, city from [customers]";
SqlDataSource1.SelectCommand += " and email in (" + Session["excelresult"].ToString() + ")";
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
Just copy paste above, do not do anything else (actually the VerifyRenderingInServerForm(Control control) should have only the definition nothing else should be there in the method body) and let me know.
I copy pasted the same code you listed in the post ... Resolved the error but excel file stiill appears as earlier means still special characters behaving as they early.
addie
Participant
1562 Points
291 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Aug 07, 2007 04:36 AM|LINK
protected void Page_Load(object sender, EventArgs e) { //SqlDataSource1.SelectCommand="select companyName, city from [customers]"; SqlDataSource1.SelectCommand += " and email in (" + Session["excelresult"].ToString() + ")"; Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { }Just copy paste above, do not do anything else (actually the VerifyRenderingInServerForm(Control control) should have only the definition nothing else should be there in the method body) and let me know.Nick Bansal
Member
182 Points
165 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Aug 07, 2007 03:49 PM|LINK
Hi
I copy pasted the same code you listed in the post ... Resolved the error but excel file stiill appears as earlier means still special characters behaving as they early.
The sample is as below:
Gridview Row:
<div>Excel Result:
Please advise...
addie
Participant
1562 Points
291 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Aug 09, 2007 04:59 AM|LINK
Give this a try and let me know:
protected void Page_Load(object sender, EventArgs e) { //SqlDataSource1.SelectCommand="select companyName, city from [customers]"; SqlDataSource1.SelectCommand += " and email in (" + Session["excelresult"].ToString() + ")"; Response.Clear(); //the line below was missing Response.ContentEncoding = System.Text.Encoding.UTF32; // Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { }Nick Bansal
Member
182 Points
165 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Aug 09, 2007 02:46 PM|LINK
Hi
I tried your code but for
Nick Bansal
Member
182 Points
165 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Aug 31, 2007 02:08 AM|LINK
I am able to resolve the issue. Appreciate your all help and concern.
bond.vinod
Member
2 Points
1 Post
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Nov 19, 2007 10:27 AM|LINK
How did u resolve that issue? please post
Aparna
Member
17 Points
4 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Nov 28, 2007 06:34 PM|LINK
I am facing similar problem.Instead of excel , i am using word.Could you please forward me the code you have written fixing this problem
buzzvishwana...
Member
2 Points
3 Posts
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Dec 05, 2007 10:34 AM|LINK
I am facing the similar problem. Can you please let me know how you could resolve the issue
soumenb
Member
2 Points
1 Post
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Dec 28, 2007 05:14 PM|LINK
How did you solve this problem. I am facing the same problem
modijaimin
Member
2 Points
1 Post
Re: Problem in special characters ehen exporting to excel in Asp.Net(C#)
Jan 08, 2008 09:52 AM|LINK
hi..... i have same problem....and i have solved it.....
you have to add one sentance:
Response.ContentEncoding = System.Text.Encoding.Default;
code:
void ExportToExcel(){
try{
if (Request.QueryString["Mode"] == "Export"){
Response.ContentType = "application/vnd.ms-excel 8.0";Response.Charset =
""; Response.ContentEncoding = System.Text.Encoding.Default; this.EnableViewState = false; System.IO.StringWriter ObjWriter = new System.IO.StringWriter();System.Web.UI.
HtmlTextWriter ObjHtmlTextWriter = new System.Web.UI.HtmlTextWriter(ObjWriter);rptUserDetails.RenderControl(ObjHtmlTextWriter);
//dgdInitiative is the Grid name which is to be exportedResponse.Write(ObjWriter.ToString());
string strhtml = ObjHtmlTextWriter.ToString();Response.AppendHeader("content-disposition", "attachment;filename=Users.xls");Response.End();
}
}
catch (System.Exception ex){
string strMsg = ex.Message;}
}