Jan
19
Written by:
Steve Gray
1/19/2010 6:03 PM
Instructions on how to get Excel to open a web page.
<body>
<form id="form1" runat="server">
<asp:Label id="lblTable" runat="server"></asp:Label>
</form>
</body>
Code behind:
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Response.ContentType = "application/vnd.ms-excel"
Dim sb As New StringBuilder
sb.Append("<table>")
sb.Append("<tr>")
sb.Append("<td style='font-weight:bold'>Order</td>")
sb.Append("<td style='font-weight:bold'>Doc Date</td>")
sb.Append("<td style='font-weight:bold'>Customer PO</td>")
sb.Append("<td style='font-weight:bold'>Lot</td>")
sb.Append("<td style='font-weight:bold;width:400px'>Subdiv</td>")
sb.Append("</tr>")
Using oDR As SqlDataReader = ...your code to populate a datareader
While oDR.Read
sb.Append("<tr>")
sb.Append("<td>" & oDR("sopnumbe") & "</td>")
sb.Append("<td>" & oDR("docdate") & "</td>")
sb.Append("<td>" & oDR("cstponbr") & "</td>")
sb.Append("<td>" & oDR("address3") & "</td>")
sb.Append("<td>" & oDR("vchrsubdivisionname") & "</td>")
sb.Append("</tr>")
End While
End Using
sb.Append("</table>")
Me.lblTable.Text = sb.ToString
End Sub