当前位置: 代码迷 >> ASP.NET >> asp.net2.0 GridView中数据导出有关问题
  详细解决方案

asp.net2.0 GridView中数据导出有关问题

热度:4353   发布时间:2013-02-25 00:00:00.0
asp.net2.0 GridView中数据导出问题!
Response.Clear()
  Response.Buffer = True
  Response.Charset = "GB2312"
  Response.AppendHeader("Content-Disposition", "attachment;filename=Container information.xls")
  Response.ContentEncoding = System.Text.Encoding.UTF8
  Response.ContentType = "application/ms-excel"
  Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
  Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
  Me.GridView1.RenderControl(oHtmlTextWriter)
  Response.Output.Write(oStringWriter.ToString)
  Response.Flush()
  Response.End()

我在ASP.NET 2.0使用以上方法将GridView中的数据导出到EXCEL文件中,但导出的文件中,有时候个别的excel文件中的中文字符是乱码。用了UTF7 整个excel文件都是乱码!

请各位大哥不吝赐教!!

------解决方案--------------------------------------------------------
Gridview到处excel的实例:地址
------解决方案--------------------------------------------------------
Response.ContentEncoding = System.Text.Encoding.UTF8

换成

Response.ContentEncoding = System.Text.Encoding.gb2312,

如果不行只有到config里面设置了
  相关解决方案