在維護舊OA的過程當中,客戶須要添加一個新功能,簡單點就是經過導入exl,而後讀取到裏面的數據,節省錄入的時間。sql
開始的時候想經過js導入exl數據到表單裏面,上網百度了一下,沒找到一個能用的。即便能夠使用,也存在兼容問題。因此使用了一下方法ide
<%
dim conn1 '定義第二個鏈接變量
set conn1=CreateObject("ADODB.Connection")
conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 5.0;Data Source="&Server.MapPath("../UserInfo/user.xls")'要導入的EXCEL表名稱Fang.xlsit
sql = "SELECT * FROM [Sheet1$]" '要導入的Excel數據裏面的表的名稱,後面必定要加$
set rs = conn1.execute(sql)
while not rs.eof
Response.Write "0"&rs(0)&"<Br>"
Response.Write "1"&rs(1)&"<Br>"
Response.Write "2"&rs(2)&"<Br>"
Response.Write "3"&rs(3)&"<Br>"
Response.Write "4"&rs(4)&"<Br>"
Response.Write "5"&rs(5)&"<Br>"
Response.Write "6"&rs(6)&"<Br>"
Response.Write "7"&rs(7)&"<Br>"
Response.Write "8"&rs(8)&"<Br>"
Response.Write "9"&rs(9)&"<Br>"
Response.Write "10"&rs(10)&"<Br>"
Response.Write "11"&rs(11)&"<Br>"
Response.Write "12"&rs(12)&"<Br>"
Response.Write "13"&rs(13)&"<Br>"
Response.Write "14"&rs(14)&"<Br>"
Response.Write "15"&rs(15)&"<Br>"
Response.Write "16"&rs(16)&"<Br>"
Response.Write "17"&rs(17)&"<Br>"
Response.Write "18"&rs(18)&"<Br>"
Response.Write "19"&rs(19)&"<Br>"
Response.Write "20"&rs(20)&"<Br>"
Response.Write "21"&rs(21)&"<Br>"
Response.Write "22"&rs(22)&"<Br>"
Response.Write "23"&rs(23)&"<Br>"
Response.Write "24"&rs(24)&"<Br>"
Response.Write "25"&rs(25)&"<Br>"
rs.movenext io
Response.Flush
wend
set rs = nothing變量
sql2 = "SELECT * FROM [Sheet2$]" '導入的Excel數據裏面的Sheet表的數據
set rs2 = conn1.execute(sql2)
while not rs2.eof
Response.Write "0"&rs2(0)&"<Br>"
Response.Write "0"&rs2(1)&"<Br>"
Response.Write "0"&rs2(2)&"<Br>"
Response.Write "0"&rs2(3)&"<Br>"
rs2.movenext
Response.Flush
wend
set rs2 = nothing百度
conn1.close
set conn1 = nothing 表單
%>方法
若是哪位有更加好的方法歡迎分享,尤爲是js讀取exl方面。im