vb-把DataTable里的内容导出到EXCEL

Private   Sub   toExcel(ByVal   tb   As   DataTable) 
                
Dim   dgrid   As   System.Web.UI.WebControls.DataGrid   =   Nothing 
                
Dim   context   As   System.Web.HttpContext   =   System.Web.HttpContext.Current 
                
Dim   strOur   As   System.IO.StringWriter   =   Nothing 
                
Dim   htmlWriter   As   System.Web.UI.HtmlTextWriter   =   Nothing 
                
If   Not   IsNothing(tb)   Then 
                        context.Response.ContentType   
=   "application/vnd.ms-excel " 
                        context.Response.ContentEncoding   
=   System.Text.Encoding.UTF8 
                        context.Response.Charset   
=   " " 

                        strOur   
=   New   IO.StringWriter 
                        htmlWriter   
=   New   System.Web.UI.HtmlTextWriter(strOur) 
                        dgrid   
=   New   DataGrid 
                        dgrid.DataSource   
=   tb.DefaultView 
                        dgrid.AllowPaging   
=   False 
                        dgrid.DataBind() 

                        dgrid.RenderControl(htmlWriter) 
                        context.Response.Write(strOur.ToString) 
                        context.Response.End() 
                
End   If 
        
End   Sub
posted @ 2007-11-13 17:52  Nina  阅读(933)  评论(0编辑  收藏  举报