hi...
I am Exporting chinese data to Microsoft Excel....while exporting sometimes chinese chars appears as special chars in the excel sheet and sometimes not.I have tried lot many thing for making it consistent.
I have used following code.
DataTable oDt;
Response.Clear();
Response.Buffer=true;
Response.AddHeader("content-disposition", "attachment;filename=file.xls");
//Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentEncoding = Encoding.GetEncoding("gb2312");
System.IO.StringWriter stringWrite =
new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
StringBuilder sbHTML =
new StringBuilder();
//Creating string with HTML in it for Export
ResourceManager rm; //For getting localized data
rm =
new ResourceManager("MyProj.Resources.myFile",this.GetType().BaseType.Assembly);
sbHTML.Append("<table border='2'>");
sbHTML.Append("<tr>");
sbHTML.Append("<td align=center style='FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: white; BACKGROUND-COLOR: #528ee7; WIDTH:215px'>" + rm.GetString("lblName") + "</td>");
sbHTML.Append("<td align=center style='FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: white; BACKGROUND-COLOR: #528ee7; WIDTH:85px'>" + rm.GetString("lblSurname") + "</td>");
sbHTML.Append("</tr>");
rm.ReleaseAllResources();
rm =
null;
foreach(DataRow dr in oDt.Rows)
{
sbHTML.Append("<tr>");
sbHTML.Append("<TD align=left>" + dr["Name"] + "</TD>");
sbHTML.Append("<TD align=left>" + dr["Surname"] + "</TD>");
sbHTML.Append("</tr>");
}
sbHTML.Append("</table>");
Response.Write(sbHTML.ToString());
Response.End();
Please anybody...suggest a consistent solution for this problem.