在 vb.net 中从 HTML 表导出到 Excel

发布于 2024-12-09 16:54:50 字数 480 浏览 0 评论 0原文

我是 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

I am a newbie in the asp.net world.
I have any asp.net application where I get data from a stored procedure in a datatable.
I would like to populate the data in an HTML table and then export it to excel.

Unfortunately these have to be done the long winded way (each column individually), since the data is modified based on user login credentials, before it is exported to excel.

Here is what I have (pretty basic)

<table>
  <tr>
    <td>EmployeeID</td>
    <td>EmployeeFirstName</td>
    <td>EmployeeLastName</td>
    <td>EmployeeLastName</td>
  </tr>
</table>  

If DataTable.HasRows Then
.....
.....
End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-12-16 16:54:50

要将其填充到 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

To populate it to the HTML table you must create the table dynamically from the VB server side code. you must define amount of cells and rows from your stored procedure.

you basically have to define your Html table like this example and populate it with the info from your stored procedure.

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

and than add it to the Me panel.

here is the link how to export html to excel http://www.devx.com/tips/Tip/14235

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文