Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2008, 08:24 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp to excel

Hi, I'm trying to output my query and get it to go to an excel file, but it simply outputs the web table, with no error. I am specifying Response.ContentType = "application/vnd.ms-excel" in the code PRIOR to <html>...

Any suggestions?


<%
    Set db = Server.CreateObject("ADODB.Connection")
    db.ConnectionString = "DSN=workout_CostSaving.mdb"
    db.Open
    Set rs = Server.CreateObject("ADODB.Recordset")

    sql = "select * from the_bird "
    rs.Open sql, db
    Response.ContentType = "application/vnd.ms-excel"
%>
<html>
<table>
    <tr>
    <%
   ' Loop through each Field, printing out the Field Names
    For i = 0 to rs.fields.count - 1
    %>
    <td><% = rs(i).name %></td>
    <% next %>
     </tr>
    <%

    while not rs.eof
    %>
    <tr>
    <% For i = 0 to rs.fields.count - 1
    %>
    <TD VALIGN=TOP><% = rs(i) %></TD>
    <% Next %>

    </TR>
    <%
    rs.MoveNext

    wend

    rs.Close
    db.close
    %>




 
Old September 12th, 2008, 02:58 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You just have to *tell* the browser that you want it as a file.

<%
...
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition", "attachment;filename=whatEver.xls"...
%>
 
Old September 17th, 2008, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ty






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP to Excel BUT show Excel grid lines mat41 Classic ASP Basics 8 May 31st, 2009 05:56 PM
ASP - Excel to Database cancer10 Classic ASP Databases 4 March 18th, 2007 11:07 PM
Excel Hyperlinks in ASP JoseLuisR Classic ASP Professional 3 December 26th, 2006 12:44 AM
ASP to Excel - excel output formatting issue mat41 Classic ASP Professional 0 August 13th, 2006 06:41 AM
ASP to Excel sienaluke Classic ASP Basics 2 March 24th, 2004 12:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.