我给你代码,不用打开EXCEL进程,不过要用到FSO,(我一直用得很好)代码如下:
<%
server.scripttimeout=100000000
sub dataIntoSqlServer_ceritificate(strFileName,strSheetName,myConn)
'定义
dim myConnection
dim strName
dim rsXsl,rsSql
dim str_Xsl,str_Sql
dim myConn_Xsl
dim cmd
dim i,j
dim maxId
strName=strFileName
set myConnection=server.createobject("adodb.connection")
set rsXsl=Server.Createobject("ADODB.Recordset")
set rsSql=Server.CreateObject("ADODB.Recordset")
set cmd=Server.CreateObject("ADODB.Command")
cmd.ActiveConnection=myConn
myConn_Xsl="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strName & ";Extended Properties=Excel 8.0"
'myConn_Xsl="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application("ASP_Directory") & "chapter05/database/" & strName & ";Extended Properties=Excel 8.0"
'打开连接
myConnection.open myConn_Xsl
'打开表
str_Xsl="select * from ["& strSheetName &"$]"
rsXsl.open str_Xsl,myConnection,1,1
j=1
Do While not rsXsl.eof
'取出最大值
str_Sql="select Max(id) as maxId from fubiao"
rsSql.open str_Sql,myConn,1,3
If Not rsSql.Eof Then
If not isNull(rsSql("maxId")) Then
maxId=Clng(rsSql("maxId"))+1
Else
maxId=1
End if
else
maxId=1
End if
rsSql.close'//关闭对象
'加入数据库
str_Sql="insert into fubiao values("&maxId&",'"&rsXsl(1)&"','"&rsXsl(3)&"','"&rsXsl(4)&"','"&rsXsl(5)&"','"&rsXsl(6)&"','"&rsXsl(7)&"','"&rsXsl(8)&"','"&rsXsl(9)&"','"&rsXsl(10)&"','"&rsXsl(11)&"','"&rsXsl(12)&"','"&rsXsl(13)&"','"&rsXsl(14)&"','"&rsXsl(15)&"','"&rsXsl(16)&"','"&rsXsl(17)&"','"&rsXsl(18)&"','"&rsXsl(19)&"','"&rsXsl(20)&"','"&rsXsl(21)&"','"&rsXsl(22)&"','"&rsXsl(23)&"','"&rsXsl(24)&"','"&rsXsl(25)&"','"&rsXsl(26)&"','"&rsXsl(27)&"')"
cmd.CommandText=str_Sql
cmd.Execute()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
j=j+1
rsXsl.movenext
Loop
response.write "共导入<font color='red'>" & j-1 & "</font>条记录.<br/>"
response.write "<a href=javascript:history.back()>确定</a>"
set rsXsl=nothing
set rsSql=nothing
set myconnection=nothing
set cmd=nothing
end sub
file1="'"&request.form("filename2")&"'"
strtj=mid(request.form("filename2"),instrrev(file1,"/"),(instrrev(file1,".")-instrrev(file1,"/")-1))
if file1="" then
response.write "请选择您要导入的Excel表!<p></p>"
%>
<a href=javascript:history.back()>上一页</a>
<%
response.end
end if
'respons.write "'"&request.form("filename")&"'"
myconn="DRIVER={SQL SERVER};SERVER=(local);uid=sa;pwd=sa;DATABASE=qjgsj_data"
dataIntoSqlServer_ceritificate file1,""&strtj&"",myconn
%>