Solved

ASP to show Excel .xls file on the web

Posted on 2000-04-03
4
1,761 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now