在本地测试时没有问题的,一发布在IIS上再导就发现乱码了,求解?
//清除客户端当前显示 Response.Clear(); //作为附件输出,filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc .xls .txt .htm Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); //显示标头 //设置显示的字和内容要存的形式 // Response.ContentEncoding = Encoding.Default;//输出内容的编码为默认编码 //Response.ContentType = "application/vnd.xls"; Response.ContentType = "application/vnd.ms-excel"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.Charset = "GB2312";//定义输出字符集 System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView1.AllowPaging = false; //查询数据 Select(); GridView1.RenderControl(htmlWrite); Response.Clear(); Response.Write("" + stringWrite.ToString()); Response.End();
指定到处编码格式。
输出时的格式都写了