datagrid导出成excel表出现乱码
代码如下:
Private Sub export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles export.Click
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = "GB2312"
Me.EnableViewState = False
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("ZH-CN", True)
Dim sw As New System.IO.StringWriter(myCItrad)
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
Dim nCur As Integer = DataGrid1.CurrentPageIndex
Dim nSize As Integer = DataGrid1.PageSize
DataGrid1.AllowPaging = False
binddata3()
DataGrid1.RenderControl(hw)
DataGrid1.AllowPaging = True
DataGrid1.CurrentPageIndex = nCur
DataGrid1.PageSize = nSize
binddata3()
Response.Write(sw.ToString())
Response.End()
End Sub