ASP download to Excel error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Robinson

    ASP download to Excel error

    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.Conten tType 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.Buffe r = True
    %>
    <!-- #INCLUDE FILE="Includes/DataConnections .asp" -->
    <!-- #INCLUDE FILE="Includes/myFunctions.asp " -->
    <%
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    'Response.AddHe ader "Content-Disposition","a ttachment;filen ame=Recharge.xl s"
    dim arrRecharge,
    fldHead,thisfie ld,numcols,numr ows,colcounter, rowcounter,show null,showblank, x
    set objConn = server.CreateOb ject("ADODB.Con nection")
    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%"><t r>
    <%'Put Headings On The Table of Field Names
    for each fldHead in objRS.fields %>
    <td><%=fldHead. name%></td>
    <%next%>
    </tr>
    <%
    CloseAll
    showblank="&nbs p;"
    shownull="-null-"
    FOR rowcounter= 0 TO numrows%>
    <tr>
    <% FOR colcounter=0 to numcols
    thisfield=arrRe charge(colcount er,rowcounter)
    if isnull(thisfiel d) then
    thisfield=shown ull
    end if
    if trim(thisfield) ="" then
    thisfield=showb lank
    end if%>
    <td><%=thisfiel d%></td>
    <%NEXT%>
    </tr>
    <%Next%>
    </table>





  • Paul Robinson

    #2
    Re: ASP download to Excel error

    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

    "Paul Robinson" <alitor99@NOSPA MHEREbtinternet .com> wrote in message
    news:%23N8WqYCP EHA.2960@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > 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.Conten tType 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.Buffe r = True
    > %>
    > <!-- #INCLUDE FILE="Includes/DataConnections .asp" -->
    > <!-- #INCLUDE FILE="Includes/myFunctions.asp " -->
    > <%
    > Response.Conten tType = "applicatio n/vnd.ms-excel"
    > 'Response.AddHe ader[/color]
    "Content-Disposition","a ttachment;filen ame=Recharge.xl s"[color=blue]
    > dim arrRecharge,
    >[/color]
    fldHead,thisfie ld,numcols,numr ows,colcounter, rowcounter,show null,showblank, x[color=blue]
    > set objConn = server.CreateOb ject("ADODB.Con nection")
    > 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%"><t r>
    > <%'Put Headings On The Table of Field Names
    > for each fldHead in objRS.fields %>
    > <td><%=fldHead. name%></td>
    > <%next%>
    > </tr>
    > <%
    > CloseAll
    > showblank="&nbs p;"
    > shownull="-null-"
    > FOR rowcounter= 0 TO numrows%>
    > <tr>
    > <% FOR colcounter=0 to numcols
    > thisfield=arrRe charge(colcount er,rowcounter)
    > if isnull(thisfiel d) then
    > thisfield=shown ull
    > end if
    > if trim(thisfield) ="" then
    > thisfield=showb lank
    > end if%>
    > <td><%=thisfiel d%></td>
    > <%NEXT%>
    > </tr>
    > <%Next%>
    > </table>
    >
    >
    >
    >
    >[/color]


    Comment

    Working...