C
Colin Steadman
I'm building a standard HTML table using ASP (I know this isn't an ASP
group but bare with me). This page is called RESULTS.ASP. Below the
table is a button which allows users to send the contents of the table
to Excel for analysis, sorting, graphs ect..
This all works fine, except that I think my method of doing this is
badly wrong.
Basically to make this work, when the user clicks the button, I
redirect to a page called:
EXPORT_TO_EXCEL.ASP
This ASP page re-runs the query so that it can output the results to
Excel. I have copied the contents of this page below.
The problem is, its not very efficient re-running the query in
EXPORT_TO_EXCEL.ASP to get data that has already been returned in
RESULTS.ASP. So I'm wondering if I could somehow pass the table I've
already created in RESULTS.ASP to instead EXPORT_TO_EXCEL.ASP instead.
Does anyone know if this is possible?
TIA,
Colin
===========================================================================
<%
Response.ContentType = "application/vnd.ms-excel"
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=(ovms.mdb)"
rs.Open Session("SQLfromLastQuery"),conn
'-- make data table for excel.
If Not rs.EOF Then
rs.MoveFirst
response.write "<table bgcolor='eeeeee'>"
response.write " <tr>"
For n = 0 to rs.Fields.Count -1
response.write " <td><b>" & rs.Fields(n).Name & "</b></td>"
Next
response.write " </tr>"
rs.MoveFirst
Do While Not rs.EOF
response.write " <tr>"
For n = 0 to rs.Fields.Count -1
response.write " <td>" & rs.Fields(n).Value & "</td>"
Next
rs.MoveNext
response.write " </tr>"
Loop
response.write "</table>"
Else
response.write "No data were found."
End If
%>
===========================================================================
group but bare with me). This page is called RESULTS.ASP. Below the
table is a button which allows users to send the contents of the table
to Excel for analysis, sorting, graphs ect..
This all works fine, except that I think my method of doing this is
badly wrong.
Basically to make this work, when the user clicks the button, I
redirect to a page called:
EXPORT_TO_EXCEL.ASP
This ASP page re-runs the query so that it can output the results to
Excel. I have copied the contents of this page below.
The problem is, its not very efficient re-running the query in
EXPORT_TO_EXCEL.ASP to get data that has already been returned in
RESULTS.ASP. So I'm wondering if I could somehow pass the table I've
already created in RESULTS.ASP to instead EXPORT_TO_EXCEL.ASP instead.
Does anyone know if this is possible?
TIA,
Colin
===========================================================================
<%
Response.ContentType = "application/vnd.ms-excel"
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=(ovms.mdb)"
rs.Open Session("SQLfromLastQuery"),conn
'-- make data table for excel.
If Not rs.EOF Then
rs.MoveFirst
response.write "<table bgcolor='eeeeee'>"
response.write " <tr>"
For n = 0 to rs.Fields.Count -1
response.write " <td><b>" & rs.Fields(n).Name & "</b></td>"
Next
response.write " </tr>"
rs.MoveFirst
Do While Not rs.EOF
response.write " <tr>"
For n = 0 to rs.Fields.Count -1
response.write " <td>" & rs.Fields(n).Value & "</td>"
Next
rs.MoveNext
response.write " </tr>"
Loop
response.write "</table>"
Else
response.write "No data were found."
End If
%>
===========================================================================