如题:
当导出的 excel 多于7行,或更多时,中文能正常显示。但如果小于这个行数,则中文就一定会显示为乱码.
导出的代码如下:
string fname = poname+fromdate+"-"+todate;
fname = fname.Replace("/","");
fname += ".xls";
Response.Clear();
Response.Buffer= true;
Response.Charset="UTF-8";
Response.AppendHeader("Content-Disposition","attachment;filename="+fname);
Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
当导出的 excel 多于7行,或更多时,中文能正常显示。但如果小于这个行数,则中文就一定会显示为乱码.
导出的代码如下:
string fname = poname+fromdate+"-"+todate;
fname = fname.Replace("/","");
fname += ".xls";
Response.Clear();
Response.Buffer= true;
Response.Charset="UTF-8";
Response.AppendHeader("Content-Disposition","attachment;filename="+fname);
Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-7");
非常感谢wuyq11