📄 importtable.asp
字号:
<%
dim action,excelpath,sheet,edate
action=trim(request.querystring("action"))
excelpath=trim(request.form("excelpath"))
sheet=trim(request.form("sheet"))
edate=trim(request.form("edate"))
select case action
case "daoru":call exctoacc(excelpath,sheet)
end select
%>
<%
function exctoacc(excpath,sheet)
Dim conn,connstr
Dim excconn
Dim excStrConn,strConn
Dim excrs,rs
Dim excSql
Set excconn=Server.CreateObject("ADODB.Connection")
Set excrs = Server.CreateObject("ADODB.Recordset")
excStrConn="Driver={Microsoft Excel Driver (*.xls)};DriverId=790; DBQ="&Server.MapPath(excpath)
excconn.Open excStrConn
excSql="select * from ["&sheet&"$]" '查询excel语句
excrs.Open excSql,excconn,2,2
Set conn=Server.CreateObject("ADODB.Connection")
connstr = "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("database/data.asp")
conn.Oopen connstr
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM StudentInfo"
rs.open sql,conn,3,3
do while Not excrs.EOF
rs.addnew
if edate="" then
for i=0 to excrs.Fields.Count-1
rs(i+1)=excrs(i)
next
else
for i=0 to excrs.Fields.Count-1
rs(i+1)=excrs(i)
rs(5)=edate
next
end if
rs.update
excrs.MoveNext
Loop
rs.close
set rs=nothing
excrs.close
set excrs=nothing
excConn.close
set excConn=nothing
response.write "<script language=javascript>"
response.write "alert('Excel表中的数据已经成功导入到数据库中!');"
response.write "location.href='ImportUserTable.asp';"
response.write "</script>"
End function
%>
<script language="JavaScript">
function check()
{
if (daoruf.excelpath.value=="")
{
alert("请输入Excel表的预处理数据路径!\n如果没有上传,请先上传Excel表再操作!");
daoruf.excelpath.focus();
return false;
}
if (daoruf.sheet.value=="")
{
alert("请输入数据表名!");
daoruf.sheet.focus();
return false;
}
return true;
}
</script>
<style type="text/css">
<!--
body {
background-image: url(images/back.gif);
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-repeat: repeat;
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css" />
<form action="?action=daoru" method="post" name="daoruf" id="daoruf" onsubmit="return check();">
<strong>从Excel表导入人员信息</strong>
<table width="600" border="0" cellpadding="2" cellspacing="0" bgcolor="#6666FF">
<tr>
<td>
<table width="600" border="1" cellpadding="5" cellspacing="2" bgcolor="#CCCCFF">
<tr>
<td width="200" height="60" align="right" bgcolor="#FFFFFF">Excel表上传至服务器<br>并预处理:</td>
<td width="400" bgcolor="#FFFFFF">
<iframe align=middle src="upload/uploadexcel.asp" frameborder=no width=400 scrolling=no height=40></iframe>
<br>预处理数据路径:<input name="excelpath" type="text" id="excelpath" size="30"></td>
</tr>
<tr>
<td width="200" height="20" align="right" bgcolor="#FFFFFF">数据表名:</td>
<td bgcolor="#FFFFFF"><input name="sheet" type="text" id="sheet" value="sheet1"> 如:Sheet1</td>
</tr>
<tr>
<td width="200" align="right" bgcolor="#FFFFFF">录取时间:</td>
<td valign="top" bgcolor="#FFFFFF">
<input name="edate" type="text" id="edate" value="<%response.write date()%>">
该处为空则录取时间为Excel表中的时间</td>
</tr>
<tr align="center">
<td height="23" colspan="2" bgcolor="#FFFFFF">
<input type="submit" name="Submit" value="导入数据库">
<input type="button" name="back" value="返回" onclick="history.go(-1)"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -