CodeAve.com CodeAve.com - ASP - Read/Write
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Create Word on the Server
Active Server Pages allow for the easy ability to create dynamic views of your data on a web server, but you can also create word and excel documents on the server. This can be particularly useful if you wish to distribute your information on CD or in document form. The following example will utilize our state info db. After reading the contents of the db instead of writing output to the browser html text is written to the server with the .doc file extension. The first seven observations (state) will have their own dynamically created word document with its corresponding info displayed as well. A table of contents page is also created (in the browser) for easy navigation around all the word documents. The current time (server time) is also added to show that all the word documents are created dynamically.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<html>
<title>CodeAve.com(Create Word on Server)</title>
<body bgcolor="#FFFFFF">
<%
' Name of the access db being queried
accessdb="state_info"

' Connection string to the access db
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

' Query the states table from the state_info db
sql = "select state,statename,capital,year,order from states "

' Execute the sql
rs.Open sql, cn

' Move to the first record
rs.MoveFirst

' For net loop to create seven word documents from the record set
' change this to "do while not rs.eof" to output all the records
' and the corresponding next should be changed to loop also

for documents= 1 to 7
' Creates a text file on the server with the state abbreviation
' as the name for the ouput document
file_being_created= rs("state") & ".doc"

' create a file system object
set fso = createobject("scripting.filesystemobject")

' create the text file - true will overwrite any previous files
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

' Writes the db output to a .doc file in the same directory
act.WriteLine("<html><title>CodeAve.com(" & rs("statename") & " State Info)</title>")
act.WriteLine("<body bgcolor='#FFFFFF'> " )
act.WriteLine("State: " & rs("statename") & "<br>" )
act.WriteLine("Abbreviaton: " & rs("state") & "<br>" )
act.WriteLine("Capital: " & rs("capital") & "<br>")
act.WriteLine("Entered the Union in "& rs("year") & "<br>")
act.WriteLine("Number in order of entrance into the Union "& rs("order") & "<br>")
act.WriteLine("Page created on: " & now ())
act.WriteLine("</body></html>")

' close the object
act.close

' Writes the links to the newly created pages in the browser
response.write "<a href='" & rs("state") & ".doc'>" & rs("statename") & "</a> (.doc) &nbsp;" & now() & "<br>"

' move to the next record
rs.movenext

' return to the top of the for - next loop
' change this to "loop" to output all the records
' and the corresponding for statement above should be changed also
next
%>
</body>
</html>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3