Response.Clear();
    Response.Buffer = true;
    Response.Charset = "GB2312";
    Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
    // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
    Response.ContentEncoding = System.Text.Encoding.UTF7;
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    this.GridView1.RenderControl(oHtmlTextWriter);
    Response.Output.Write(oStringWriter.ToString());
    Response.Flush();
    Response.End();
这样试试

解决方案 »

  1.   


    回 lbaeolus() 按照你那方法试了.发现问题还是存在的.没变化
      

  2.   

    Public Sub GridViewToExcel(ByVal ctl As Control, ByVal FileName As String)
            HttpContext.Current.Response.Clear()
            HttpContext.Current.Response.Buffer = True
            HttpContext.Current.Response.Charset = "GB2312"
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default
            'Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>")
            HttpContext.Current.Response.ContentType = "application/ms-excel"
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" & Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) & ".xls")
            ctl.Page.EnableViewState = False
            Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
            Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
            ctl.RenderControl(oHtmlTextWriter)
            HttpContext.Current.Response.Write(oStringWriter.ToString())
            HttpContext.Current.Response.Flush()
            HttpContext.Current.Response.End()
        End Sub
    调用时GridViewToExcel(控件id,表名)
      

  3.   

     Response.Clear();
            HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
            HttpContext.Current.Response.Charset = "UTF-7";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            grdsendbox.Page.EnableViewState = false;
            System.Globalization.CultureInfo Cul = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter sw = new System.IO.StringWriter(Cul);
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
            grdsendbox.RenderControl(hw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();