- ASP - Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Create Excel 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 .xls file extension. All observations (states) will be a unique row within the excel that is created with its corresponding info displayed as well. A link to the new document is created (in the browser) for easy navigation to the new document. The current time (server time) is also displayed to show that the excel document was created dynamically.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<title> Excel on Server)</title>
<body bgcolor="#FFFFFF">
' Name of the access db being queried

' 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

' Name for the ouput document
file_being_created= "states.xls"

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

' create the text file - true will overwrite any previous files
' Writes the db output to a .xls file in the same directory
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

' All non repetitive html on top goes here
act.WriteLine("<table border=""1"">")
act.WriteLine("<th nowrap>State</th>")
act.WriteLine("<th nowrap>Abbreviaton</th>")
act.WriteLine("<th nowrap>Capital</th>")
act.WriteLine("<th nowrap>Year Entered</th>")
act.WriteLine("<th nowrap>Entrance Number</th>")

' 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

act.WriteLine("<td align=""right"">" & rs("statename") & "</td>" )
act.WriteLine("<td align=""right"">" & rs("state") & "</td>" )
act.WriteLine("<td align=""right"">" & rs("capital") & "</td>")
act.WriteLine("<td align=""right"">"& rs("year") & "</td>")
act.WriteLine("<td align=""right"">"& rs("order") & "</td>")

' move to the next record

' 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

' All non repetitive html on top goes here

' close the object (excel)

' Writes a link to the newly created excel in the browser
response.write "<a href='states.xls'>States</a> (.xls) has been created on " & now() & "<br>"




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 is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

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