Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am facing a problem in Export to Excel from a gridview data.
I have the data with forward slash in the data ("/") in one of the columns which is diplaying like a character ”⁄” (slant is more in this case) instead of “/”. The same file is uploading in some other application and this character is taking as some junk characters at their end.

For Ex:
Actual Value:25515/DT9NN2BJ_PCDG_2015
Displayed Value in Excel:25515⁄DT9NN2BJ_PCDG_2015

The difference in above values is in "slash". please observe it carefully.

Please help ASAP.

here is my code.

DataGrid dgExport = new DataGrid();
dgExport.DataSource = dtExport;
dgExport.DataBind();

string Excelfilename = "Test_Excel_Export" + DateTime.Now;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition:", "attachment; filename=" + Excelfilename + ".xls");
Response.Charset = "";
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();          System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dgExport.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End



Though I have added below two lines of code, still the same problem persists.

C#
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());



Regards
Surya
Posted
Updated 7-Dec-14 22:20pm
v2

1 solution

Export Data with Encoding it

C#
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());


refer this link

http://asheej.blogspot.in/2012/03/how-to-export-gridview-data-to-excel.html[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900