[英]How to write non-english characters to HttpResponse
我在写一些中文字符到http响应时遇到了问题。 我将application / vnd.ms-excel设置为ContentType。
当我查看excel文件时,我看不到我写的字符。 我也试过使用不同的编码,但它不起作用。 我错过了什么吗?
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();
}
你试过把它放在web.config
吗?
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" responseHeaderEncoding="utf-8" />
然后输出为UTF8
我们设法通过使用Response.BinaryWrite而不是Response.Write来解决它。 多谢你们!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.