Response.ContentEncoding = System.Text.Encoding.UTF7; 
Response.ContentEncoding =System.Text.Encoding.getEnconde("gb2312")试试

解决方案 »

  1.   

      public void DataTable2Excel(System.Data.DataTable dtData, String FileName)
        {
            System.Web.UI.WebControls.GridView dgExport = null;
            //当前对话 
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            //IO用于导出并返回excel文件 
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;        if (dtData != null)
            {
                //设置编码和附件格式 
                System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8);//作用是方式中文文件名乱码
                curContext.Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.UTF7;
                curContext.Response.Charset = "GB2312";            //导出Excel文件 
                strWriter = new System.IO.StringWriter();
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);            //为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的GridView 
                dgExport = new System.Web.UI.WebControls.GridView();
                dgExport.DataSource = dtData.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();            //下载到客户端 
                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }
      

  2.   

    Response.ContentEncoding = System.Text.Encoding.UTF7;
    改为
    Response.ContentEncoding = System.Text.Encoding.UTF8;
      

  3.   

    另外在HTML代码里需要加上 EnableEventValidation = "false"  否则会出现异常<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" EnableEventValidation = "false" AutoEventWireup="true" CodeFile="PlaneAnalysisShow.aspx.cs" Inherits="OLAP_PlaneAnalysisShow"%>
      

  4.   

       Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls\""); 
    改成
       Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.Default) + ".xls\""); 
      

  5.   

    这个问题楼主怎么解决的啊,我也遇到这样的问题啊,在office2007中打开是乱码
      

  6.   

    在你点击导出execl时,先保存后再次打开就没乱码了。
      

  7.   

    这一句的问题
    Response.ContentEncoding = System.Text.Encoding.UTF7; 
    设置成UTF8就不会有乱码了
      

  8.   

     protected void Button1_Click(object sender, EventArgs e)//这是导出按钮    {
      #region 导出到Excel
            Response.Clear();
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
           
            Response.AddHeader("content-disposition",
                "attachment;filename=MyProjectFileName.xls");
            Response.ContentType = "application/vnd.xls";        System.IO.StringWriter stringWrite = new System.IO.StringWriter();        System.Web.UI.HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);
            G_cli1.AllowPaging = false;
            G_cli1.Columns[1].Visible = false;//为什么加这句话呢
    这句话的实际意思是第二列不导出 如果不加 导出是乱码 你把你不需要的一列禁了以后试试
    为什么禁了一列导出就不乱码了 原因我也不清楚 仅仅是自己实践证明的!!!
           
            Bind();        G_cli1.RenderControl(htmlWrite);        Response.Write(stringWrite.ToString());
            Response.End();        G_cli1.AllowPaging = true;
            Bind();
            #endregion
        }
     public override void VerifyRenderingInServerForm(Control control)//这也必须加上
        {    }