Excel download for chinese printing unwanted characters?
I am trying to download chinese data from database to excel. But data is coming with different charecters in Excel like this
œèŽžå¸‚è¯šé€šè®¡ç®—æœºæŠ€æœ¯å’¨è¯¢æœåŠ¡æœ‰é™å…¬å¸
Here is the my code for download excel. I don't understand what's wrong in my code.
dg.AllowPaging = False
dg.AllowSorting = False
dg.AllowCustomPaging = False
dg.AutoGenerateColumns = True
dg.HeaderStyle.Font.Bold = True
dg.HeaderStyle.Font.Underline = True
dg.DataSource = sqlDs.Tables(0)
dg.DataB开发者_如何转开发ind()
dg.RenderControl(htmlWrite)
Response.Clear()
Response.ClearContent()
Response.AddHeader("content-disposition", "attachment;filename=FullExtract_" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & ".xls")
Response.ContentType = "application/octet-stream"
'Response.ContentType = "application/excel"
Response.BinaryWrite(System.Text.UnicodeEncoding.UTF8.GetBytes(stringWrite.ToString()))
Response.End()
Haven't try with Chineese but I had similar problems with Turkish data.The code below works well for me. You can find detailed info here . Hope this helps.
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=Test.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
FormView1.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
精彩评论