當前位置:編程學習大全網 - 源碼下載 - ASP文件 怎麽寫數據到EXCEL文件裏?

ASP文件 怎麽寫數據到EXCEL文件裏?

<%

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

%>

  • 上一篇:windows本地沒有hadoop 下怎麽配置linux 下的hadoop home
  • 下一篇:中國制造業的發展現狀
  • copyright 2024編程學習大全網