日期:2014-05-17 浏览次数:20992 次
If Request.QueryString("action")="do" Then Dim conn Dim StrConn Dim Rs Dim Sql Dim i Dim ExName ExName = Request.Form("ExName") ExTName = Request.Form("ExTName") Set conn =Server.CreateObject("ADODB.Connection") '开始使用的StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("excel/"&ExName) 'StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("excel/"&ExName)";& Extended Properties="&Excel 8.0;HDR=Yes;IMEX=1" '读取所有数据,这个稳定 StrConn ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("excel/"&ExName)&";Extended Properties='Excel 8.0;HDR=1;IMEX=1'" conn.Open StrConn Set rs = Server.CreateObject("ADODB.Recordset") Sql="select * from ["&ExTName&"$]" rs.Open Sql,conn,1,1 if Err.Number <> 0 then response.write "<p><p><p><p><p><br><br><br><br><br><center><br><br>对不起,发生错误。<br><br>错误提示:请确认您选择的EXCEL数据表格式是否标准!</center>" response.write "<p><p><p><p><br><br><br><center><a href='javascript:history.back(-1)'>点击返回</a></center>" response.end End if %> <body bgcolor="#C3DAF9"> <form method=post action="in.Asp" name=form1 onSubmit="return chk(this)"> <div align="center"> <table width="80%" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#FFFFFF" bordercolorlight="#CCCCCC"> <tr align=center height=20> <td bgcolor="#698CC3"><font size="5" face="楷体_GB2312">程序已经读出的Excel中的数据列表,请点击 最下面的 导入到数据库 按钮</font></td> </tr> <tr> <td align="center"> <input name=Count type=hidden value="<%=rs.Fields.Count%>" size="4"> <% for i=0 to rs.Fields.Count-1 %> <input name="ExFName<%=i%>" value="<%=Rs(i).Name%>" readonly size="7" Class="fr2" align=center> <% Next Response.Write "</td></tr></table><table width=80% border=1 cellspacing=0 cellpadding=4 align=center bordercolordark=#FFFFFF bordercolorlight=#CCCCCC>" Response.Write "<tr bgcolor=white><td align=center>" Dim a a=0 do while not rs.eof for i=0 to rs.Fields.Count-1 if i mod rs.Fields.Count = 0 then Response.Write "<br/>" End if %> <input name="ExCName<%=a%>" value="<%=Rs(i)%>" size="7" Class="fr2"> <% a = a +1 next rs.MoveNext Loop Response.Write "</td></tr><tr><td align=center><input name='A' type=hidden value="&a&"><input type=submit value=导入到数据库 Class=fr2></td></tr></table>" Response.Write "<input type='hidden' name='ExTname' value="&ExTname&">" Response.Write "</form>" rs.close set rs=nothing conn.close set StrConn=nothing Response.End End if