[英]Exporting to from HTML table to excel in vb.net
我是asp.net的新手。
我有任何asp.net應用程序,都可以從數據表中的存儲過程中獲取數據。
我想將數據填充到HTML表中,然后將其導出到excel。
不幸的是,由於數據是在導出到excel之前根據用戶登錄憑據進行修改的,因此必須漫長的路要走(每個列分別進行)。
這是我所擁有的(非常基本)
<table>
<tr>
<td>EmployeeID</td>
<td>EmployeeFirstName</td>
<td>EmployeeLastName</td>
<td>EmployeeLastName</td>
</tr>
</table>
If DataTable.HasRows Then
.....
.....
End If
要將其填充到HTML表中,必須從VB服務器端代碼動態創建該表。 您必須從存儲過程中定義單元格和行的數量。
您基本上必須像本示例一樣定義Html表,並使用存儲過程中的信息填充它。
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
' Create a new HtmlTable object.
Dim table1 As New HtmlTable()
' Start adding content to the table.
Dim row As HtmlTableRow
Dim cell As HtmlTableCell
For i As Integer = 1 To 8
' Create a new row and set its background color.
row = New HtmlTableRow()
For j As Integer = 1 To 8
' Create a cell and set its text.
cell = New HtmlTableCell()
cell.InnerHtml = "Row: " & i.ToString() & "<br />Cell: " & j.ToString()
' Add the cell to the current row.
row.Cells.Add(cell)
Next
' Add the row to the table.
table1.Rows.Add(row)
Next
' Add the table to the page.
Me.Controls.Add(table1)
End Sub
並將其添加到“我”面板中。
這是如何將html導出到excel的鏈接http://www.devx.com/tips/Tip/14235
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.