以下是代码片段:
<%Option Explicit%>
<html>
<head>
<title>操纵Excel</title>
</head>
<body>
<h2 align="center">显示Excel文件示例</h2>
<table border="1" width="90%" align="center">
<tr align="center" bgcolor="#E6E6E6">
<td>学号</td><td>姓名</td><td>数学</td><td>语文</td><td>英语</td><td>总分</td>
</tr>
<%
‘’建立Connection对象
Dim db,rs,strSql
Set db = Server.CreateObject("ADODB.Connection")
db.Open "Driver={Microsoft Excel Driver (*.xls)};Dbq=" & Server.MapPath("Mark.xls")
‘’打开记录集,表名一定要以"[表名$]"的格式
strSql="Select * From [Sheet1$]"
Set rs=db.Execute(strSql)
‘’循环读取所有行
Do While Not rs.EOF
Response.Write "<tr align=‘’center‘’>"
Response.Write "<td>" & rs("学号") & "</td>"
Response.Write "<td>" & rs("姓名") & "</td>"
Response.Write "<td>" & rs("数学") & "</td>"
Response.Write "<td>" & rs("语文") & "</td>"
Response.Write "<td>" & rs("英语") & "</td>"
Response.Write "<td>" & rs("总分") & "</td>"
Response.Write "</tr>"
rs.MoveNext
Loop
‘’关闭对象
rs.Close
Set rs=nothing
db.Close
Set db=Nothing
%>
</table>
</body>
</html>
以下是mark.xls的文件截图