Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 24th, 2007, 08:38 AM
Systemdownnn Systemdownnn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 334 Systemdownnn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 12 h 37 m 42 sec
Reputation Power: 4
Thumbs up Exporting From Access Db to Excell in asp

Well here is a Sample of View_Enquiry.asp that shows the result from a database which is linked to export_to_excel.asp that handles the export of data to excel.

You can change it to meet your needs.

View_Enquiry.asp

asp Code:
Original - asp Code
  1.  
  2. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  3.  
  4. <html>
  5.  
  6. <body><table border=0>
  7. <tr><td><a href="export_to_excel.asp">Export</a></td></tr>
  8. <tr><td>
  9. <%
  10. dim Cn,Rs
  11. set Cn=server.createobject("ADODB.connection")
  12. set Rs=server.createobject("ADODB.recordset")
  13. Cn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("database/dbname.mdb")
  14. Rs.open "select * from Tbl_subscription",Cn,1,3
  15. if Rs.eof <> true then
  16. response.write "<table border=0>"
  17. while not Rs.eof
  18. response.write "<tr><td>" & Rs.fields("subscriptionID") & "</td><td>" & Rs.fields("firstName") & "</td><td>" & Rs.fields("lastName") & "</td><td>" & Rs.fields("email") & "</td></tr>"
  19. Rs.movenext
  20. wend
  21. response.write "</table>"
  22. end if
  23. set rs=nothing
  24. Cn.close
  25. %>
  26. </td></tr>
  27. </table>
  28. </body>
  29. </html>




export_to_excel.asp

asp Code:
Original - asp Code
  1. <%@ Language=VBScript %>
  2. <%
  3. dim Cn,Rs
  4. set Cn=server.createobject("ADODB.connection")
  5. set Rs=server.createobject("ADODB.recordset")
  6. Cn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("database/dbname.mdb")
  7. Rs.open "select * from Tbl_subscription",Cn,1,3
  8. Response.ContentType = "application/vnd.ms-excel"
  9. Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"
  10. if Rs.eof <> true then
  11. response.write "<table border=0>"
  12. while not Rs.eof
  13. response.write "<tr><td>" & Rs.fields("subscriptionID") & "</td><td>" & Rs.fields("firstName") & "</td><td>" & Rs.fields("lastName") & "</td><td>" & Rs.fields("email") & "</td></tr>"
  14. Rs.movenext
  15. wend
  16. response.write "</table>"
  17. end if
  18. set rs=nothing
  19. Cn.close
  20. %>

Last edited by Systemdownnn : April 1st, 2007 at 09:31 AM.

Reply With Quote
  #2  
Old March 29th, 2007, 01:00 PM
pitbullpuppy pitbullpuppy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 3 pitbullpuppy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 55 sec
Reputation Power: 0
Question Re: Exporting From Access Db to Excell in asp

Great timing on this post! I just finished my first on-line database and I'm looking to add more functionality. I created the two files above as instructed. The first file worked except that the formatting is all honked up. (Not a problem, I'll make it pretty later). But the second file - export_to_excel.asp - is giving me an error message:

Response object error 'ASP 0156 : 80004005'
Header Error
/fa22qa/soar/export_to_excel.asp, line 18
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.


Line 18 in my file is:

Response.ContentType = "application/vnd.ms-excel"

The header content in my file looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "(URL address blocked: See forum rules)">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html xmlns="(URL address blocked: See forum rules)">

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>


Can you see what might be causing this error?

Thanks!
pbp

Reply With Quote
  #3  
Old April 1st, 2007, 09:37 AM
Systemdownnn Systemdownnn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 334 Systemdownnn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 12 h 37 m 42 sec
Reputation Power: 4
Post your whole code on the export_to_excel.asp page and i'll see whats happening!

Reply With Quote
  #4  
Old April 10th, 2007, 03:01 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,274 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1Folding Points: 358052 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 13 h 10 m 23 sec
Reputation Power: 1792
try adding Response.Buffer=True to your code.

Reply With Quote
  #5  
Old April 10th, 2007, 11:12 AM
pitbullpuppy pitbullpuppy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 3 pitbullpuppy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 55 sec
Reputation Power: 0
Quote:
Originally Posted by Systemdownnn
Post your whole code on the export_to_excel.asp page and i'll see whats happening!


I hope you can see this...

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "(URL address blocked: See forum rules)">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html xmlns="(URL address blocked: See forum rules)">

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<%
dim Cn,Rs
set Cn=server.createobject("ADODB.connection")
set Rs=server.createobject("ADODB.recordset")
Cn.open "PROVIDER=sqloledb;SERVER=myserver;UID=myid;PWD=myp  w;DATABASE=mydb"
Rs.open "select * from Tbl_SOAR_Surveillance",Cn,1,3
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"
if Rs.eof <> true then
response.write "<table border=0>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("SurvID") & "</td><td>" & Rs.fields("InspName") & "</td><td>" & Rs.fields("SupvName") & "</td><td>" & Rs.fields("SurvDate") & "</td><td>" & Rs.fields("swbs") & "</td><td>" & Rs.fields("Q1") & "</td><td>" & Rs.fields("Q2") & "</td><td>" & Rs.fields("Q3") & "</td><td>" & Rs.fields("Q4") & "</td><td>" & Rs.fields("Q5") & "</td><td>" & Rs.fields("Q6") & "</td><td>" & Rs.fields("Q7") & "</td><td>" & Rs.fields("Q8") & "</td><td>" & Rs.fields("Q9") & "</td><td>" & Rs.fields("Q10") & "</td><td>" & Rs.fields("Q11") & "</td><td>" & Rs.fields("Q12") & "</td><td>" & Rs.fields("Q13") & "</td><td>" & Rs.fields("Q14") & "</td><td>" & Rs.fields("Q15") & "</td><td>" & Rs.fields("empnum") & "</td><td>" & Rs.fields("comments") & "</td></tr>"
Rs.movenext
wend
response.write "</table>"
end if
set rs=nothing
Cn.close
%> 
</body>
</html>


Thanks for your help

Reply With Quote
  #6  
Old April 11th, 2007, 05:40 AM
Systemdownnn Systemdownnn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 334 Systemdownnn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 12 h 37 m 42 sec
Reputation Power: 4
dont add the html headers...

just have this code

asp Code:
Original - asp Code
  1. <%@ Language=VBScript %>
  2. <%
  3. dim Cn,Rs
  4. set Cn=server.createobject("ADODB.connection")
  5. set Rs=server.createobject("ADODB.recordset")
  6. Cn.open "PROVIDER=sqloledb;SERVER=myserver;UID=myid;PWD=myp    w;DATABASE=mydb"
  7. Rs.open "select * from Tbl_SOAR_Surveillance",Cn,1,3
  8. Response.ContentType = "application/vnd.ms-excel"
  9. Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"
  10. if Rs.eof <> true then
  11. response.write "<table border=0>"
  12. while not Rs.eof
  13. response.write "<tr><td>" & Rs.fields("SurvID") & "</td><td>" & Rs.fields("InspName") & "</td><td>" & Rs.fields("SupvName") & "</td><td>" & Rs.fields("SurvDate") & "</td><td>" & Rs.fields("swbs") & "</td><td>" & Rs.fields("Q1") & "</td><td>" & Rs.fields("Q2") & "</td><td>" & Rs.fields("Q3") & "</td><td>" & Rs.fields("Q4") & "</td><td>" & Rs.fields("Q5") & "</td><td>" & Rs.fields("Q6") & "</td><td>" & Rs.fields("Q7") & "</td><td>" & Rs.fields("Q8") & "</td><td>" & Rs.fields("Q9") & "</td><td>" & Rs.fields("Q10") & "</td><td>" & Rs.fields("Q11") & "</td><td>" & Rs.fields("Q12") & "</td><td>" & Rs.fields("Q13") & "</td><td>" & Rs.fields("Q14") & "</td><td>" & Rs.fields("Q15") & "</td><td>" & Rs.fields("empnum") & "</td><td>" & Rs.fields("comments") & "</td></tr>"
  14. Rs.movenext
  15. wend
  16. response.write "</table>"
  17. end if
  18. set rs=nothing
  19. Cn.close
  20. %> 

hope it helped

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Exporting From Access Db to Excell in asp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |