I am having problems in writing some Chinese characters to http response. I set application/vnd.ms-excel to ContentType.
When I view the excel file, I can’t see the characters that I have written. I have tried using different encoding as well but it doesn’t work. Am I missing something?
protected void Button1_Click(object sender, EventArgs e)
{
HttpResponse response = Page.Response;
response.Clear();
response.ClearHeaders();
response.ContentEncoding = System.Text.UnicodeEncoding.GetEncoding("GB2312");
response.Charset = "GB2312";
response.AddHeader("Content-Disposition", "attachment;filename=myfile.xls");
response.ContentType = "application/vnd.ms-excel;charset=GB2312";
response.Write("盈亏 你好你好你怎么样");
response.Flush();
response.End();
}
We managed to solve it by using Response.BinaryWrite instead of Response.Write. Thanks guys!