ASP download to Excel error

Discussion in 'ASP General' started by Paul Robinson, May 17, 2004.

  1. 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>
    Paul Robinson, May 17, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    > 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>
    >
    >
    >
    >
    >
    Paul Robinson, May 20, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A B
    Replies:
    1
    Views:
    2,896
    Peter O'Reilly
    May 13, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,616
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  3. George Homorozeanu

    ASP.NET + Excel Download

    George Homorozeanu, Jun 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    8,782
    santhanamk
    Mar 17, 2010
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,500
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. yuki999
    Replies:
    0
    Views:
    421
    yuki999
    Jan 2, 2008
Loading...

Share This Page