步骤:
1.先上传
2.建立excel记录集
3.建立sql server数据库记录集
4.读取数据并添加到数据库中
5.清空连接
今天把部分代码整理如下:
Choose.asp
Export_Clothes.asp
Choose.asp部分代码:
<table width="100%" height="250" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td><form method="post" action="Export_Clothes.asp" enctype="multipart/form-data">
<table width="100%" height="47" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="24" bgcolor="#FFFFCC">导入到工作服维护表</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">选择EXCEL文件:
<input type="file" /><br /><input type="submit" value="上传" /><input type="hidden" value="exportcloth" /></td>
</tr>
</table>
</form>
<form method="post" action="Export_Clothes.asp" enctype="multipart/form-data">
<table width="100%" height="47" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="24" bgcolor="#FFFFCC">导入到人员信息表</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">选择EXCEL文件:
<input type="file" /><br /><input type="submit" value="上传" /><input type="hidden" value="exportusers" /></td>
</tr>
</table>
<br />
<font color="#FF0000">*</font> 注意:请正确选择相关的EXCEL文件导入。
</form>
</td>
</tr>
</table>
Export_Clothes.asp部分代码:
Function ExportUsers
set file=upload.file("file_users")
if file.FileSize>0 then
if GetFileType(file.FileName) <> ".xls" then
Call ShowMsg("警告:只能上传Excel文件!",0,"")
end if
CALL DelFile("../../upload/export_users.xls")
file.saveAs Server.mappath("../../upload/export_users.xls")
excconn.Open "Driver={Microsoft Excel Driver (*.xls)};HDR=Yes;DBQ="&Server.MapPath("../../upload/export_users")
set excrs = excconn.execute("select * from [Sheet1$]")
myconn.conn.execute("delete from GA_hr_info")
rs.open "select * from GA_hr_info",MyConn.Conn,1,3
do while not excrs.EOF
if excrs(0) <> "" and isnull(excrs(0)) = false then
rs.addnew
rs("taskid") = 0
rs("hrid") = excrs(0)
rs("dspname") = replace(excrs(1)," ","")
rs("dept") = excrs(2)
rs("joindate") = excrs(3)
rs("status") = "A"
rs.update
end if
excrs.MoveNext
Loop
Call ShowMsg("成功:人员数据上传成功!",1,"Choose.asp")
else
Call ShowMsg("警告:请不要上传空文件!",0,"")
end if
End Function
评论