Solved

ASP to show Excel .xls file on the web

Posted on 2000-04-03
4
1,765 Views
Last Modified: 2008-01-09
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?  
0
Comment
Question by:yjh123
4 Comments
 
LVL 3

Expert Comment

by:Flubbadub
ID: 2682168
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.
0
 

Expert Comment

by:enterume
ID: 2682484
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?
0
 

Author Comment

by:yjh123
ID: 2682581
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.
0
 
LVL 1

Accepted Solution

by:
carled earned 100 total points
ID: 2683141
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:
<html>


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


<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
rsTemp.open 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">
<tr>
<%'Put Headings On The Table of Field Names
for i=0 to howmanyfields %>
<td><b><%=rstemp(i).name %></b></td>
<% next %>
</tr>

<%'Now lets grab all the records
%><tr>
<%do while not rstemp.eof %>
<%for i = 0 to howmanyfields%>
<td><%=rstemp(i)%></td>
<%next
rstemp.movenext%>
</tr>
<%loop %>
</table>
</body>
</html>



Hope this does the trick!

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question