<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

解决方案 »

  1.   

    up!http://support.microsoft.com/default.aspx?scid=kb;EN-US;317719
      

  2.   

    http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asphttp://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=567&lngWId=10
      

  3.   

    你的情况我也遇到过,程序代码没有错,只是因为你的DataGrid中的数据中有在Excel中不能正常显示的字符而已。我以前也以为是程序的错误呢。
      

  4.   

    有时,如果你动态生成Excel表的名称如果太长,也会导致乱码产生,并且此时如果你下载则不能下载,我就遇到过这种情况,原因不明.
      

  5.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    //export to excelResponse.Clear();
    Response.Buffer= true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "";
    this.EnableViewState = false;System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);this.ClearControls(dg);
    dg.RenderControl(oHtmlTextWriter);Response.Write(oStringWriter.ToString());Response.End();
    }
      

  6.   

    Public Function ExportToExcel(ByVal ds As System.Data.DataSet, ByVal DataGrid1 As DataGrid, ByVal SchoolID As Integer)
            Dim oView As New DataView(ds.Tables(0))
            DataGrid1.DataSource = oView
            DataGrid1.DataBind()        Response.ContentType = "application/vnd.ms-excel"
            Response.Charset = ""
            Response.ContentEncoding = System.Text.Encoding.Default '这行是解决乱码的关键        Me.EnableViewState = False
            Dim tw As New System.IO.StringWriter()
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            DataGrid1.RenderControl(hw)
            Response.Write(tw.ToString())
            Response.End()
        End Function
      

  7.   

    已经解决了,加上
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">就行了,哈哈,送分了
      

  8.   

    'Form DataSet To Excel
        Public Sub WriteDataBaseToExcelByStream(ByVal daReader As System.Data.SqlClient.SqlDataReader, ByVal FileName As String)
            Dim numbercols As Integer = daReader.FieldCount
            Dim row As Integer = 2
            Dim i As Integer = 0
            Dim fileLine As String        Dim Fname As String = Request.PhysicalApplicationPath + "Exported\" + FileName
            Dim drm As New System.IO.StreamWriter(Fname, False, System.Text.Encoding.Unicode)        For i = 0 To numbercols - 1
                fileLine += daReader.GetName(i).ToString() + ","
            Next
            drm.WriteLine(fileLine)        While (daReader.Read())
                fileLine = ""
                For i = 0 To numbercols - 1
                    If daReader.GetValue(i).GetType() Is Nothing Then
                        fileLine += """"
                    Else
                        If daReader.GetValue(i).GetType Is GetType(String) Then
                            fileLine += """" + daReader.GetValue(i).ToString() + ""","
                        Else
                            fileLine += daReader.GetValue(i).ToString() + ","
                        End If
                    End If
                Next
                drm.WriteLine(fileLine)
                row += 1
            End While
            drm.Flush()
            drm.Close()
        End Sub