To make this work, the spreadsheet needs to have a named region, which becomes
the tablename, which includes the first row as fieldnames.
The following code did the trick:
My File DSN (XL.DSN) is:
=============================
[ODBC]
DRIVER=Microsoft Excel Driver (*.xls)
UserCommitSync=Yes
Threads=3
SafeTransactions=0
ReadOnly=1
PageTimeout=5
MaxScanRows=8
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=excel 5.0
DriverId=790
=============================
The ASP code is:
=============================
<%
' create a connection
Set Excelsheet = Server.CreateObject("ADODB.Connection")
' open a connection
Excelsheet.Open "FileDSN=" & Server.MapPath("XL.DSN") &
";DBQ=D:\MyDir\MyWorkbook.XLS"
SQLExcel = "Select * FROM [TopProducers]"
' execute the SQL query
Set RSExcel = Excelsheet.Execute(SQLExcel)
%>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<table border=1>
<tr>
<td><b>Producer</b></td>
<td><b>Written Premium</b></td>
<%
Do Until RSExcel.EOF
If RSExcel(0) <> "" or RSExcel(1) <> "" then
response.write "<tr><td>" & RSExcel(0) & "</td>"
response.write "<td align=right>" & FormatCurrency(RSExcel(1),2) &
"</td></tr>"
End if
RSExcel.MoveNext
Loop
%>
</table>
<br>
<img src="graph.gif">
</body>
</html>
|