ASP to show Excel .xls file on the web

I am a newbie to ASP programming.  Can anyone show me a simple script that will read an Excel .xls file in the same directory as the ASP file and show the content on the web?

Maybe simple ASP script with sample xls file ready go would be perfect for me!

Thanks in advance.

So I need NT server to run this or can windows98 personal server can handle it?  Please excuse my ignorance... I am currently running Apache on Linux. Any luck with ASP?  
Who is Participating?
carledConnect With a Mentor Commented:
I've managed to do this - it's a very rough example but it works on IIS4 and personal web server.  The only way I could get it to work was by using named ranges in Excel, which means that each time you add a record you need to change the range to include that record (the Excel help file has info on named ranges).  Someone in this group can probably tell you a way of working around this.

The excel file is this: (hopefully this will reformat on your screen ok)

Property Ref      Address      Office      On sale since      Price
L9912      14 Latimer Close, Narborough, Leicester      Leicester      13-Jan-99      £45,950
L9918      3 Ridley Close, Birstall, Leicester      Leicester      9-Feb-99      £85,000
O2918      14 Trewitt Way, Beasdale, Shelthorpe      Loughborough      9-Dec-98      £55,000
B1102      17 Island Way, Burton-upon-Trent      Burton      4-Mar-99      £19,500
B1103      19 Breeze Way, Burton-upon-Trent      Burton      4-Mar-99      £19,500

The asp code I've used is this:

<title>Property List test - Excel link</title>

<body bgcolor="#CCCCFF">
<H1>Property List</H1>
<p> </p>
' Set Variables
Dim DataSource, OnMenu, Query

'Set up name to call data returned (in this case it's 'DataSource')
Set DataSource =  Server.CreateObject("ADODB.Connection")
Set rsTemp =  Server.CreateObject("ADODB.Recordset")

'Set DSN-less connection (prevents the need for setting up dsn on server)
DSNtemp="DRIVER={Microsoft Excel Driver (*.xls)}; "

'set path to spreadsheet containing data (property.xls)
DSNtemp=dsntemp & "DBQ=" & server.mappath("property.xls")
'this sets the path to look in the current directory - you could give it an absolute path if you wanted, like c:\data\property.xls)

'Set fields you want to return - in this case '*' meaning all
Query = "SELECT * FROM propertylist"

'Open connection
DataSource.Open DSNtemp Query,Datasource,3,3

'Set recordset name (to 'OnMenu' in this case)
'Set OnMenu = DataSource.Execute(Query)
howmanyfields=rstemp.fields.count -1

<table width="600" border="1" cellspacing="1" cellpadding="1">
<%'Put Headings On The Table of Field Names
for i=0 to howmanyfields %>
<td><b><%=rstemp(i).name %></b></td>
<% next %>

<%'Now lets grab all the records
<%do while not rstemp.eof %>
<%for i = 0 to howmanyfields%>
<%loop %>

Hope this does the trick!

If your client browser id IE then you don't need any special code to display an XLS!  Just point the browser at the URL of the xls file and Whammo! (nOTE On Navigator you will get an "Open File/Save File" dialog.
What you mean is read the data from .XLS and view it brower? you want to do sth like database access to .XLS file or try to display only the .XLS file?
yjh123Author Commented:
I need to be able to read certain part of excel file and show on the web.  Not as a whole, but a certain fields based on certain criteria. (e.g, date=4/3/00)
I will be embedding this on a table on a webpage.  So downloding or open from the location is not what I had in mind.

Next phase would be getting input from the browser and write it back to the excel file...  I know it is getting complicated, but hope to achieve one at a time...

Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.