ASP download to Excel error

P

Paul Robinson

I am trying to download a table of data from an ASP page into Excel. The
link opens Excel OK and creates a worksheet with the name of the ASP page,
but no data is transferred. If I remove (comment out) the
Response.ContentType line from my code, then the table appears on the asp
page. I have added my code below. if anyone could tell me what I am doing
wrong, I will be grateful




<% Option Explicit
'Response.Buffer = True
%>
<!-- #INCLUDE FILE="Includes/DataConnections.asp" -->
<!-- #INCLUDE FILE="Includes/myFunctions.asp" -->
<%
Response.ContentType = "application/vnd.ms-excel"
'Response.AddHeader "Content-Disposition","attachment;filename=Recharge.xls"
dim arrRecharge,
fldHead,thisfield,numcols,numrows,colcounter,rowcounter,shownull,showblank,x
set objConn = server.CreateObject("ADODB.Connection")
strSQLproc = "EXECUTE procRepRecharge"
objConn.Open strConnect
Set objRS = objConn.Execute(strSQLproc)
arrRecharge = objRS.GetRows
numcols=ubound(arrRecharge,1)
numrows=ubound(arrRecharge,2)
%>
<table border="1" cols="<%=ubound(arrRecharge,1)%>" width="100%"><tr>
<%'Put Headings On The Table of Field Names
for each fldHead in objRS.fields %>
<td><%=fldHead.name%></td>
<%next%>
</tr>
<%
CloseAll
showblank="&nbsp;"
shownull="-null-"
FOR rowcounter= 0 TO numrows%>
<tr>
<% FOR colcounter=0 to numcols
thisfield=arrRecharge(colcounter,rowcounter)
if isnull(thisfield) then
thisfield=shownull
end if
if trim(thisfield)="" then
thisfield=showblank
end if%>
<td><%=thisfield%></td>
<%NEXT%>
</tr>
<%Next%>
</table>
 
P

Paul Robinson

Problem is now solved. If anyone is interested, for future reference, the
problem was caused by one of the Include files which contained <html> tags
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top