分享

把DataTable里的内容导出到EXCEL

 thy 2007-11-13
我也来一个,把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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多