View Single Post
  #1 (permalink)  
Old June 15th, 2006, 11:53 AM
neversummer84 neversummer84 is offline
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem exporting to excel

I'm query an access database, which is working fine displaying as web content. I would like to export the results to excel, and basically just added the lines below to the one displaying to the web

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"

I have the code below, which does not give errors, but produces an empty exel file. the only thing it produces are the table headings and the links Any ideas?

<%@ Language=VBScript %>
<%Option explicit
Dim oRs,oRs2, conn, conn2, connect, strSQL, count, oddeven, bgcolor

set conn=server.CreateObject("ADODB.connection")
set conn2=server.CreateObject("ADODB.connection")

connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("sheep.mdb") & ";Persist Security Info=False"
conn.Open connect
conn2.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("info.mdb") & ";Persist Security

Info=False"
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"
%>
<html>
<head>
<title></title>

</head>
<body>
<center>Search Results</center><br>
<table border=1 cellspacing=0 cellpadding=3>
<tr bgcolor="#ADD8E6">
<td nowrap><b>1</b></td>
<td nowrap><b>2</b></td>
<td nowrap><b>3</b></td>

</tr>

    <%
    count=count+1

    Set oRs=server.CreateObject("adodb.recordset")

    strSQL = "SELECT DISTINCT * FROM tblInfo WHERE Name= '" & request("name") & "'AND Description = '" &

request("description") & "'AND Location = '" & request("location") & "' "

    oRs.Open strSQL, conn2

    Do while not oRs.EOF

    count=count+1
    oddeven=right(count,1)
    select case oddeven
    case "1","3","5","7","9"
    bgcolor = "#E8E8E8"


    case else
    bgcolor = "#FFFFFF"
    end select

    Response.Write "<tr bgcolor='" & bgcolor & "'><td nowrap> " & oRs ("Name") & "</td><td nowrap>" & oRs ("Description") & "</td><td nowrap>" & oRs ("Location") & "</td></tr>"

    oRs.MoveNext

    loop
    oRs.Close
    Set oRs = Nothing



    %>

</table><br><br>
<a href="sheepexcel.asp">[Export to Excel]</a>
<br><br>
<center><a href="sheepquery.asp">[Search for another product]</a> <a href="index.htm">[Home]</a></center>
</body>
</html>

Reply With Quote