为什么导出excel 在本地不会乱码,上传到服务器却乱码了,也不知道是哪出问题了
//Response.Clear();
//Response.AddHeader("Content-Disposition", "inline;filename=EService.xls");
//Response.Buffer = true;
//Response.Charset = "GB2312";
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//Response.ContentType = "application/vnd.xls";
//System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//Page.EnableViewState = false;
//this.rptEserver.RenderControl(htmlWrite);
//Response.Write(stringWrite.ToString());
//Response.End();
[解决办法]
private void Export() { string strActionID = listActionName.SelectedItem.Text.ToString() + ".xls"; Response.Clear(); Response.Buffer = true; Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + Server.UrlPathEncode(strActionID) + "\""); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/ms-excel";[color=#FF0000] Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");[/color] this.EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); this.gvResult.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End(); }
[解决办法]
应该是编码不一样。
[解决办法]