基本的代码都有不过总是要出错,希望有正确的代码,谢谢。

解决方案 »

  1.   

    public void Export(){Response.Clear();Response.Buffer = true;Response.Charset = "GB2312";Response.AppendHeader("Content-Disposition", "attachment;filename=Data.xls");Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");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);GridView1.RenderControl(oHtmlTextWriter);Response.Write(oStringWriter.ToString());Response.End();
    }