3个回答
展开全部
<% if request("action")<>"do" then%>
<form action="" method="post">
<input type="file" name="exname" />
<input name="action" type="hidden" value="do" />
<input type="submit" name="Submit" value="提交" />
</form>
<%
else
dim exname
exname=request("exname")
Dim cn,oConn,connstr
'打开XLS.
Set cn = Server.CreateObject("ADODB.Connection")
cn.Provider = "Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source=" & exname & ";" & _
"Extended Properties=Excel 8.0;"
cn.Open
'打开MDB.
connstr="DBQ="+server.MapPath("data1.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set oConn=server.CreateObject("ADODB.CONNECTION")
oConn.open connstr
'读取数据.
set rsRead=server.CreateObject("ADODB.Recordset")
rsRead.Open "select * from [Sheet1$]",cn,1,1
%>
<table width="256" height="108" border="1" bordercolor="#FFCCCC">
<tr>
<td>用户名</td>
<td>密码</td>
</tr>
<%do until rsRead.EOF
'写入数据库.
oConn.Execute("Insert into users(userid,password)Values('"& rsRead.Fields("userid")&"','" &rsRead.Fields("password") & "')" )
%>
<tr>
<td><input name="" type="text" VALUE="<%=rsread.fields("userid")%>"/></td>
<td><input name="" type="text" VALUE="<%=rsread.fields("password")%>"/></td>
</tr>
<%
rsRead.MoveNext
loop
%>
</table>
<%end if %>
EXCEL数据库的结构要和目标数据库ACCESS的结构要对应
<form action="" method="post">
<input type="file" name="exname" />
<input name="action" type="hidden" value="do" />
<input type="submit" name="Submit" value="提交" />
</form>
<%
else
dim exname
exname=request("exname")
Dim cn,oConn,connstr
'打开XLS.
Set cn = Server.CreateObject("ADODB.Connection")
cn.Provider = "Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source=" & exname & ";" & _
"Extended Properties=Excel 8.0;"
cn.Open
'打开MDB.
connstr="DBQ="+server.MapPath("data1.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set oConn=server.CreateObject("ADODB.CONNECTION")
oConn.open connstr
'读取数据.
set rsRead=server.CreateObject("ADODB.Recordset")
rsRead.Open "select * from [Sheet1$]",cn,1,1
%>
<table width="256" height="108" border="1" bordercolor="#FFCCCC">
<tr>
<td>用户名</td>
<td>密码</td>
</tr>
<%do until rsRead.EOF
'写入数据库.
oConn.Execute("Insert into users(userid,password)Values('"& rsRead.Fields("userid")&"','" &rsRead.Fields("password") & "')" )
%>
<tr>
<td><input name="" type="text" VALUE="<%=rsread.fields("userid")%>"/></td>
<td><input name="" type="text" VALUE="<%=rsread.fields("password")%>"/></td>
</tr>
<%
rsRead.MoveNext
loop
%>
</table>
<%end if %>
EXCEL数据库的结构要和目标数据库ACCESS的结构要对应
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询