本帖最后由 huangsishu 于 2009-07-29 09:02:57 编辑

解决方案 »

  1.   

     HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(ExportFileName, System.Text.Encoding.UTF8) + ".xls");            HttpContext.Current.Response.Charset = "GB2312";            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
      

  2.   

    Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(xlsFile, System.Text.Encoding.GetEncoding("gb2312")) + ".xls"); 
      

  3.   

     GridView当前页显示数据导出Excel using System.Data.SqlClient;
    using System.IO;protected void Button1_Click(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
            Response.ContentType = "application/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }//下面的代码必须加上,否则会出现错误public override void VerifyRenderingInServerForm(Control control)
            { }本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cuilei197979/archive/2009/08/04/4407952.aspx
      

  4.   

    我是把excel功能做成用户控件的,用在sharepoint上,所以没有这个函数VerifyRenderingInServerForm(Control control)
    可以重载