in this page, I am only opening an existing excel file
<%@ Import namespace ="System.Data.SqlClient" %>
<%@ Import namespace ="System.Data" %>
<%@ Import namespace ="System.Web.Security" %>
<%@ Import Namespace="System.Web" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<h2 style="FONT-FAMILY: Arial">Test Summary Report</h2>
<font style="FONT-WEIGHT: bold; FONT-FAMILY: Arial">Report Data was Updated: </font>
<form id="Form1" method="post" runat="server">
<asp:DataGrid ID="dgUpdated" Runat="server" ShowHeader="False" BorderWidth="0" Font-Names="Arial" Font-Bold="True" style="FONT-WEIGHT: bold; FONT-FAMILY: Arial" Width="227px" Height="10px"></asp:DataGrid>
<asp:DataGrid id="dgNameList" style="Z-INDEX: 101; LEFT: 7px; POSITION: absolute; TOP: 160px" runat="server" BorderWidth="1px" AutoGenerateColumns="False" BorderColor="#999999" BackColor="White" HorizontalAlign="Left" BorderStyle="Groove" CellPadding="3" GridLines="Vertical">
<FooterStyle ForeColor="Black" BackColor="Silver"></FooterStyle>
<HeaderStyle Font-Size="10pt" Font-Names="arial" Font-Bold="True" Wrap="False" ForeColor="White" BackColor="DimGray"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
<SelectedItemStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BorderStyle="Groove" BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle Font-Size="9pt" Font-Names="arial" Wrap="False" ForeColor="Black" BackColor="White"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="eventdate" SortExpression="eventdate" HeaderText="Date"></asp:BoundColumn>
<asp:BoundColumn DataField="sales" SortExpression="sales" HeaderText="Sales"></asp:BoundColumn>
<asp:BoundColumn DataField="dr_sales" SortExpression="dr_sales" HeaderText="DR Sales" ItemStyle-Wrap="false" HeaderStyle-Wrap="false"></asp:BoundColumn>
<asp:BoundColumn DataField="net_sales" SortExpression="net_sales" HeaderText="Net Sales"></asp:BoundColumn>
<asp:BoundColumn DataField="tot_ref_fee" SortExpression="tot_ref_fee" HeaderText="Total Referral Fee"></asp:BoundColumn>
<asp:BoundColumn DataField="pct_tot" SortExpression="pct_tot" HeaderText="Referral Fee Pct."></asp:BoundColumn>
<asp:BoundColumn DataField="sbs_contribution" SortExpression="sbs_contribution" HeaderText="SBS Contribution"></asp:BoundColumn>
<asp:BoundColumn DataField="pct_sbs" SortExpression="pct_sbs" HeaderText="SBS Contribution Pct."></asp:BoundColumn>
<asp:BoundColumn DataField="dist_contribution" SortExpression="dist_contribution" HeaderText="Distr Referral Fee Exp."></asp:BoundColumn>
<asp:BoundColumn DataField="pct_dist" SortExpression="pct_dist" HeaderText="Distr Referral Fee Pct."></asp:BoundColumn>
<asp:BoundColumn DataField="act_ref_sources" SortExpression="act_ref_sources" HeaderText="Active Referral Sources"></asp:BoundColumn>
<asp:BoundColumn DataField="rid" SortExpression="rid" HeaderText="Sources Referring"></asp:BoundColumn>
<asp:BoundColumn DataField="ncid" SortExpression="ncid" HeaderText="New Customers"></asp:BoundColumn>
<asp:BoundColumn DataField="new_sales" SortExpression="new_sales" HeaderText="New Sales"></asp:BoundColumn>
<asp:BoundColumn DataField="rep_sales" SortExpression="rep_sales" HeaderText="Repeat Sales"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
<asp:Button id="btnOpenExcel" runat="server" Text="View in Excel" OnClick="OpenExcel" ToolTip="Opens the Report in Excel." onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.fontWeight='normal'" style="Z-INDEX: 103; LEFT: 455px; POSITION: absolute; TOP: 59px"></asp:Button>
</form>
<script language="vb" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
Dim objConnection As sqlConnection = New sqlConnection(ConfigurationSettings.AppSettings("test"))
Dim strSQLupdate As String = "Select min(last_updated) from test"
Dim objCommand As New SqlCommand(strSQLupdate, objConnection)
objConnection.Open()
Dim objReader As sqlDataReader = objCommand.ExecuteReader()
dgUpdated.DataSource = objReader
dgUpdated.DataBind()
objReader.Close()
Dim strSQL As String = "Select * from test order by eventdate"
objCommand.CommandText = strSQL
objReader = objCommand.ExecuteReader()
dgNameList.DataSource = objReader
dgNameList.DataBind()
objConnection.Close()
End Sub
Sub OpenExcel(Source As Object, E As EventArgs)
Dim FileName As String = "test.xls"
Dim FileAndPath As String = "C:\" & FileName
'This opens the download dialoge box and allows the user'
'to download the excel sheet from the server'
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName)
Response.Flush()
'This command actually transfers the file'
Response.WriteFile(FileAndPath)
End Sub
</script>
</FONT>
<HR style="Z-INDEX: 102; LEFT: 17px; WIDTH: 162.76%; POSITION: absolute; TOP: 43px; HEIGHT: 3px; BACKGROUND-COLOR: silver" width="162.76%" SIZE="3">
</body>
</HTML>