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=" "
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>
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=" "
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>