本地测试的时候 功能是没问题的 但是一放到服务器上就出现乱码了
查看了服务器本地execl文件 内容是正常的 就是下载的时候出现乱码 
下面导出execl代码截图调用截图 剩下的就是乱码截图
在线求解决啦!!!!!!!!ASP.NETexecl乱码

解决方案 »

  1.   

    一开始就是用utf_8 也是一样乱码
      

  2.   

    下载时候指定编码,类似以下:
    Response.Clear(); 
    Response.ClearContent(); 
    Response.ClearHeaders(); 
    Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); 
    Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 
    Response.AddHeader("Content-Transfer-Encoding", "binary"); 
    Response.ContentType = "application/octet-stream"; 
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 
    Response.WriteFile(fileInfo.FullName); 
    Response.Flush(); 
    Response.End(); 
      

  3.   

       /// <summary>
            /// 文件导出
            /// </summary>
            /// <param name="page">对象页面</param>
            /// <param name="filePath">文件保存服务器路径</param>
            /// <param name="dt">数据源</param>
            /// <param name="exportFileName">导出后的文件名称</param>
            public static void ExportFile(System.Web.UI.Page page, string filePath, DataTable dt, string exportFileName)
            {
                try
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    StreamWriter sw = new StreamWriter(new FileStream(filePath, FileMode.CreateNew), System.Text.Encoding.GetEncoding("GB2312"));                sw.Write(exportFileName);
                    sw.WriteLine();                int i = 0;
                    for (i = 0; i <= dt.Columns.Count - 1; i++)
                    {
                        sw.Write(dt.Columns[i].ColumnName);
                        sw.Write('\t');
                    }
                    sw.WriteLine();                foreach (DataRow dr in dt.Rows)
                    {
                        for (i = 0; i <= dt.Columns.Count - 1; i++)
                        {
                            sw.Write(dr[i].ToString());
                            sw.Write('\t');
                        }
                        sw.WriteLine();
                    }
                    sw.Close();
                    FileDownload(page, filePath, exportFileName);
                }
                catch { }
            }
      

  4.   

     /// <summary>
            /// 文件下载
            /// </summary>
            /// <param name="page">页面参数</param>
            /// <param name="filePath">文件源路径</param>
            /// <param name="saveFileName">文件命名</param>
            public static void FileDownload(System.Web.UI.Page page, string filePath, string saveFileName)
            {
                try
                {
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        string fileExtension = filePath.Substring(filePath.LastIndexOf('.'));//后缀
                        //saveFileName = filePath.Substring(filePath.LastIndexOf(@"\"));//文件名                    page.Response.Clear();
                        page.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(saveFileName)));
                        page.Response.Charset = "utf-8";
                        page.Response.ContentEncoding = System.Text.Encoding.Default;
                        page.Response.WriteFile(filePath);
                        page.Response.End();
                    }
                }
                catch { }
            }
      

  5.   

    下载文件结束后就不要再输出其它内容了吧,不然好像附加到Excel文件里了
      

  6.   

    Refer this:
    http://www.cnblogs.com/insus/articles/1400266.htmlalso see:
    http://www.cnblogs.com/insus/archive/2013/05/14/3077826.html
      

  7.   

    在这里下了个dll  可惜不会使用 不知道有没有详细的使用例子
      

  8.   

    一开始指定了编码格式,别人的文件不一定是你指定的格式。 你试一试
    Encoding.Default 按照系统 默认的来试试
      

  9.   

    哪一个链接,就是例子:
    http://www.cnblogs.com/insus/archive/2013/05/14/3077826.html如果觉得很繁杂,再给你另外一个:
    http://www.cnblogs.com/insus/archive/2013/01/16/2862121.html太概这样子:Protected Sub Button1_Click(sender As Object, e As EventArgs)
            Dim obj As New InsusExportToExcel()  '实例化对象。
            obj.ExportToExcel(Me.RepeaterCatalog, "catalog") '传入Repeater控件以入导出的Excel文件名。
        End Sub