Question

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.DataBind()
        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()

No correct solution

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top