导出EXECL 2003正常 2007 不正常问题

 Response.ClearContent();               

  Response.Buffer = true;              

   Response.Charset = "utf-8";               

  Response.AppendHeader("Content-Disposition", "attachment; filename=EnergyReport" +                     DateTime.Now.ToString("_yyyyMMdd_HHmmss") + ".xls");                

Response.ContentEncoding = System.Text.Encoding.Default;            

     Response.ContentType = "application/ms-excel";

                gv.AllowPaging = false;           

      gv.DataBind();              

   this.EnableViewState = false;             

    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ZH-CN", true);

                System.IO.StringWriter tw = new System.IO.StringWriter(ci);          

       HtmlTextWriter hw = new HtmlTextWriter(tw);       

          gv.RenderControl(hw);

                Response.Output.Write(tw.ToString());

                gv.AllowPaging = true;              

   gv.DataBind();

                Response.Flush();             

    Response.End();

 

红色是主要的!

posted @ 2011-12-23 11:18  晴天娃娃、  阅读(359)  评论(0编辑  收藏  举报