原来写得gv导出到2003一点问题没有,导出到2007就出现全部乱码,修改的地方用红色字体标注

     public void SaveToExcel(GridView _gv,Page _page)
        {
            _page.Response.Clear();
            _page.Response.Buffer = true;
            _page.Response.Charset = "GB2312";
            _page.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
            _page.Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
            _page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            _page.Response.ContentType = "application/vnd.xls";//设置输出文件类型为excel文件。
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            _gv.RenderControl(oHtmlTextWriter);
            _page.Response.Output.Write(oStringWriter.ToString());
            _page.Response.Flush();
            _page.Response.End();

        }

posted on 2008-09-17 21:55  Dot-Boy  阅读(1958)  评论(2编辑  收藏  举报