asp讀取excel表名的實(shí)現(xiàn)代碼
更新時(shí)間:2011年09月19日 20:52:55 作者:
excel在實(shí)際中,還有大量應(yīng)用,今天就拿到一堆的excel文件,需要對(duì)里面的數(shù)據(jù)做下讀取另作他用,這里就涉及到了asp遍歷excel的所有表名。
看代碼:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
dim conn,rs,excelFileName
excelFileName=Server.MapPath("Data/test.xls")
set conn = Server.CreateObject("ADODB.Connection")
conn.connectionstring="Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info=True;Data Source=" & excelFileName & ";Extended ProPerties=""Excel 8.0;HDR=Yes;IMEX=1"";"
conn.open()
set rs=conn.OpenSchema(20)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Excel操作</title>
</head>
<body>
<%
dim i
response.write("Excel表信息字段:<br />------------------------<br />")
for i=0 to rs.fields.count-1 step 1
response.write(rs.fields(i).name&"<br />")
next
response.write("<br />Excel中的表名(Table_Name):<br />------------------------<br />")
while not rs.EOF
response.write(rs("Table_Name")&"<br />")
rs.movenext
wend
%>
</body>
</html>
復(fù)制代碼 代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
dim conn,rs,excelFileName
excelFileName=Server.MapPath("Data/test.xls")
set conn = Server.CreateObject("ADODB.Connection")
conn.connectionstring="Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info=True;Data Source=" & excelFileName & ";Extended ProPerties=""Excel 8.0;HDR=Yes;IMEX=1"";"
conn.open()
set rs=conn.OpenSchema(20)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Excel操作</title>
</head>
<body>
<%
dim i
response.write("Excel表信息字段:<br />------------------------<br />")
for i=0 to rs.fields.count-1 step 1
response.write(rs.fields(i).name&"<br />")
next
response.write("<br />Excel中的表名(Table_Name):<br />------------------------<br />")
while not rs.EOF
response.write(rs("Table_Name")&"<br />")
rs.movenext
wend
%>
</body>
</html>
相關(guān)文章
asp內(nèi)置對(duì)象 ObjectContext 事務(wù)管理 詳解
asp內(nèi)置對(duì)象 ObjectContext 事務(wù)管理 詳解...2007-11-11
ASP 代碼出現(xiàn)80040e14錯(cuò)誤的解決方法
本文減淡概述了解決80040e14錯(cuò)誤的兩種方法。2009-04-04
通過(guò)表單的做為二進(jìn)制文件上傳request.totalbytes提取出上傳的二級(jí)制數(shù)據(jù)
通過(guò)表單的做為二進(jìn)制文件上傳request.totalbytes提取出上傳的二級(jí)制數(shù)據(jù)的代碼說(shuō)明。2009-09-09
隨機(jī)提取Access/SqlServer數(shù)據(jù)庫(kù)中的10條記錄的SQL語(yǔ)句
隨機(jī)提取Access/SqlServer數(shù)據(jù)庫(kù)中的10條記錄的SQL語(yǔ)句...2006-07-07

