|
 |
asp_databases thread: how do you display a recordset in a word document
Message #1 by "jeff scott" <jeff@j...> on Wed, 19 Sep 2001 06:59:23
|
|
I need to display a recordset in a word document as it appears on a web
page.
Changing the content type doesn't work, because when saved, all the html
tags are also copied into the word document.
here's the code that displays the recordset.
<html>
<body>
<%
Response.Write("<META HTTP-EQUIV=Pragma CONTENT=no-cache>")
Response.expires = 0
Response.Write ("<TABLE BORDER=0 width=600>")
Response.Write ("<TR>")
Response.Write ("<TH align=left>FA Code</TH>")
Response.Write ("<TH align=left>Title</TH>")
Response.Write ("<TH align=left>Revision</TH>")
Response.Write ("<TH align=left>Date</TH>")
Set Databaseconnection = Server.CreateObject("ADODB.Connection")
DatabaseConnection.Open CODEBOOK_STRING
sqltemp = "SELECT * FROM Body order by Level1 & Level2 & Level3 & Level4 &
Level5"
Set CurrentRecordSet = DatabaseConnection.Execute (sqltemp)
CurrentRecordSet.MoveFirst
Do While Not CurrentRecordSet.EOF
Response.Write("<tr><td width=75>")
Response.Write(CurrentRecordSet.Fields("Level1") & CurrentRecordSet.Fields
("Level2") & CurrentRecordSet.Fields("Level3") & CurrentRecordSet.Fields
("Level4") & CurrentRecordSet.Fields("Level5"))
Response.Write("</td><td width=325>")
Response.Write(CurrentRecordSet.Fields("Title"))
Response.Write("</td><td width=100>")
Response.Write(CurrentRecordSet.Fields("Revision"))
Response.Write("</td><td width=100>")
Response.Write(CurrentRecordSet.Fields("Date"))
Response.Write("</td></tr>")
CurrentRecordSet.MoveNext
Loop
Response.Write("</table>")
%>
</body>
</html>
thank you,
jeff scott
Message #2 by "jeff scott" <jeff@j...> on Thu, 20 Sep 2001 08:35:59
|
|
I figured it out. Maybe someone will find this useful.
<!--#include file="../include/codebook.inc"-->
<!--#include file="../include/Chap15DB.inc"-->
<%
dim rs,sql
Response.buffer = true
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM Body order by Level1 & Level2 & Level3 & Level4 &
Level5"
rs.Open sql, CODEBOOK_STRING, 1, 2
Response.ContentType="application/vnd.ms-word"
'Adds header to give the document a name
response.AddHeader "content-disposition","inline;filename=allcodes.doc"
%>
<html>
<body>
<table border="1" align=left>
<th>FA Code</th>
<th>Title</th>
<th>Revision</th>
<th>Date</th>
<%
'Move to the first record
rs.movefirst
'Start a loop that will end with the last record
do while not rs.eof
Response.Write("<tr><td width=75>")
Response.Write(rs("Level1") & rs("Level2") & rs("Level3") & rs("Level4") &
rs("Level5"))
Response.Write("</td><td width=325>")
Response.Write(rs("Title"))
Response.Write("</td><td width=100>")
Response.Write(rs("Revision"))
Response.Write("</td><td width=100>")
Response.Write(rs("Date"))
Response.Write("</td></tr>")
rs.MoveNext
Loop
Response.Write("</table>")
%>
</body>
</html>
<%
'Close and set the recordset to nothing
rs.close
set rs=nothing
response.flush
response.end
%>
|
|
 |