我从网上找到一段代码,将DATAGRID导出到EXCEL,导出后发现EXCEL里除了数据全部是空白,没有了边框线,还有没有列标题。
请问怎么回事?有谁能提供更完善的代码吗?我用的是VB 代码如下:
Sub Button1_Click(sender As Object, e As System.EventArgs) 
    datagrid1.databind()
Response.Clear()
    HttpContext.Current.Response.AddHeader("Content-Disposition","attachment;filename=Excel.xls") 
          HttpContext.Current.Response.Charset ="UTF-8"
  dim resp as HttpResponse = Page.Response 
          resp.ContentEncoding = System.Text.Encoding.Default
          Response.ContentType = "application/ms-excel" 
          
          Me.EnableViewState = False 
          Dim tw As New System.IO.StringWriter() 
          Dim hw As New System.Web.UI.HtmlTextWriter(tw) 
          datagrid1.RenderControl(hw) 
          HttpContext.Current.Response.Write(tw.ToString()) 
          HttpContext.Current.Response.End() 
datagrid1.databind()
End Sub