怎么解决这个乱码?

chenjing1104 chenjing1104 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我写了一个导出,导出的名字是中文字,如果写个英文字就不是乱码,代码如下:

public void Bind()
{
string sql = "select * from userInfo";
DataTable dt = SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
StringWriter sw = new StringWriter();
sw.WriteLine("编号\t姓名\t年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["id"] + "\t" + dr["name"] + "\t" + dr["age"]);
}
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment; filename=报表.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();

}
请问各位前辈要怎么解决呀!
...全文
评论 14
收藏 已收藏
分享
返回顶部
chenjing1104
.NET社区 62,272 成员 668,968 内容