ASP.NET输出CSV文件乱码-解决方法
平台 ASP.NET
this.Response.Clear(); this.Response.Charset = "GB2312"; this.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); this.Response.AddHeader("Content-Disposition",String.Format("attachment; filename=file-{0}.csv",DateTime.Now.ToShortDateString())); this.Response.ContentType = "application/vnd.ms-excel"; string[] columns = { "序号", "姓名", "手机号码", "电子邮箱", "省份", "城市", "地区" }; const string csv = "1,2,3"; var builder = new StringBuilder(); builder.AppendLine(String.Join(",",columns)); builder.AppendLine(csv); this.Response.Write(builder); this.Response.End();
本博客内容,如需转载请务必保留超链接。Contact Me:Mail此处省略好几个字...