为什么下面的代码保存到Execl中会是烂码(中文是,数字不是,且行超过90时)(50分)

  • 主题发起人 主题发起人 mingwuyi
  • 开始时间 开始时间
M

mingwuyi

Unregistered / Unconfirmed
GUEST, unregistred user!
try
{
Response.AddHeader("Content-Disposition", "attachment;
filename=CommonAttend.
xls");
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState= true;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid.RenderControl(hw);
HttpResponse resp =Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//解决中文乱码之关键
resp.ContentType = "application/vnd.ms-excel";
resp.Write(tw.ToString());
resp.End();
}
catch(Exception E)
{
this.CustomValidator.ErrorMessage =E.Message.ToString();
this.CustomValidator.IsValid =false;
}
 
后退
顶部