纸上得来终觉浅,绝知此事要躬行。

 

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();

 

posted on 2013-11-01 10:07  JRoger  阅读(744)  评论(0编辑  收藏  举报

导航