|
我也來(lái)一個(gè),把DataTable里的內(nèi)容導(dǎo)出到EXCEL,執(zhí)行代碼就行,什么都不用改,什么都不用設(shè)置
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 |
|
|
來(lái)自: thy > 《asp.net1》