请教高手如何解决ASP.NET汇出资料到Excel中出现乱码的问题,來者有分!!!! 在线等待
duyl 2002-12-30 10:35:49
我使用的代码为
public void ExportWord(System.Web.UI.Page thisPage)
{
thisPage.Response.AppendHeader("Content-Disposition","attachment; filename=Word.doc"); //filename=Report.xls
thisPage.Response.Charset = "UTF-8";
thisPage.Response.ContentType="application/msword";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel
thisPage.Page.EnableViewState = false; //Turn off the view state.
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
thisPage.RenderControl(hw); //Get the HTML for the control.
thisPage.Response.Write(tw.ToString()); //Write the HTML back to the browser.
thisPage.Response.End();
}
因为我们要实现多国语言,在英文语系下Datagrid中的资料有中文的地方就是乱码,并且当在中文语系时,若Datagrid中的资料不多,可以正常显示中文,只要资料较多时中文就又是乱码!很困惑,速盼高手解答
另:我将汇出成的doc檔用Web方式预览,它默认的charset=windows-1252,将其变为utf-8时就可正常显示中文, excel与doc一样