扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:廖煜嵘编译 来源:天极网 2007年11月7日
关键字: Windows
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable) Response.ContentType = "application/ms-Excel" Response.AddHeader("Content-Disposition", "inline;filename=test.xls") Response.Write(ConvertDtToTDF(dt)) End Sub Private Function ConvertDtToTDF(ByVal dt As DataTable) As String Dim dr As DataRow, ary() As Object, i As Integer Dim iCol As Integer ' 输出列标题 For iCol = 0 To dt.Columns.Count - 1 Response.Write(dt.Columns(iCol).ToString & vbTab) Next Response.Write(vbCrLf) '输出数据 For Each dr In dt.Rows ary = dr.ItemArray For i = 0 To UBound(ary) Response.Write(ary(i).ToString & vbTab) Next Response.Write(vbCrLf) Next End Function End Class |
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable) Response.ContentType = "application/ms-Excel" Response.AddHeader("Content-Disposition", "inline;filename=test.xls") DataGrid1.DataSource = dt DataGrid1.DataBind() DataGrid1.RenderControl(writer) End Sub |
Response.ContentType = "application/ms-word" Response.AddHeader("Content-Disposition", "inline;filename=test.doc") |
<script language="vbscript"> Sub exportbutton_onclick Dim sHTML, oExcel, oBook SHTML = document.all.item("DataGrid1").outerhtml Set oExcel = CreateObject("Excel.Application") Set oBook = oExcel.Workbooks.Add oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML oBook.HTMLProject.RefreshDocument oExcel.Visible = true oExcel.UserControl = true End Sub </script> |
Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable) DataGrid1.DataSource = dt DataGrid1.DataBind() |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者