【问题标题】:Exporting to from HTML table to excel in vb.net在 vb.net 中从 HTML 表导出到 excel
【发布时间】:2011-10-13 00:10:14
【问题描述】:

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

【问题讨论】:

    标签: asp.net vb.net visual-studio-2008 export-to-excel


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      相关资源
      最近更新 更多