在excel文件中必须先设好字段(如:[number],[dates],[customer],[Eu number],[serial number],[Item number],[Ref],[Barcode]);
---asp导入excel
set exconn=server.CreateObject("adodb.connection")
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("alpha_request.xls") & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
exconn.open strconn---连接对象
exsql = "insert into [Sheet1$]([number],[dates],[customer],[Eu number],[serial number],[Item number],[Ref],[Barcode]) values ('"&i&"','"&rs("date_return")&"','"&rs("csname")&"','"&rs("re_number")&"','"&rs("serialnumber")&"','"&rs("itemnumber")&"','"&rs("ref")&"','"&stick_number&"')"
exconn.execute exsql---导入excel
server.ScriptTimeout=999
dim url,trueurl
fname="alpha_request.xls"
if fname<>"" then
trueurl=server.MapPath(fname)
else
Response.end
end if
set objFso=server.CreateObject("scripting.filesystemobject")
set fn=objFso.GetFile(trueurl)
flsize=fn.size
flname="alpha_request"&date()&".xls"
set fn=nothing
set objFso=nothing
set objStream=server.CreateObject("adodb.stream")
objStream.Open
objStream.Type=1
objStream.LoadFromFile trueurl
pname=year(date())&"-"&month(date())&"-"&day(date())&" "&hour(time())&"-"&minute(time())&"-"&second(time)
'response.Write pname
'response.End()
set fso=CreateObject("scripting.filesystemobject")
if (fso.FileExists(Server.MapPath("alpha_request.xls"))) then
set fs=fso.getfile(Server.MapPath("alpha_request.xls"))
fs.copy Server.MapPath("_notes/"&pname&".xls")
fso.DeleteFile (Server.MapPath("alpha_request.xls"))
end if
if (fso.FileExists(Server.MapPath("alpha_request_backup.xls"))) then
set fs=fso.getfile(Server.MapPath("alpha_request_backup.xls"))
fs.copy(Server.MapPath("alpha_request.xls"))
set fs=nothing
set fso=nothing
end if
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename="&flName
Response.AddHeader "Content-Length", flsize
Response.CharSet="utf-8"
Response.ContentType=ContentType
Response.BinaryWrite objStream.Read
Response.Flush
Response.Clear()
objStream.Close
set objStream=nothing ---下载excel