aspexcel导入到数据库
⑴ ASP里,将Excel导入到Access数据库
下面连接到test.xls表sheet1$
'表后面要加个$的,一定要加这个符号
Set
conn
=
Server.CreateObject("ADODB.Connection")
conn.Open
"Driver={Microsoft
Excel
Driver
(*.xls)};ReadOnly=0;DBQ="
&
Server.MapPath("test.xls")
sql1="select
*
from
[sheet1$]"
Set
rs
=
Server.CreateObject("ADODB.Recordset")
rs.Open
SQL1,
conn,
3,
3
'下面连接到atest.mdb表user
curDir
=
Server.MapPath("atest.mdb")
Set
conn1
=
Server.CreateObject("ADODB.Connection")
conn1.Open
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
&
curDir
Set
rs1
=
Server.CreateObject("ADODB.Recordset")
Set
rs1.ActiveConnection
=
conn1
rs1.Source
=
"select
*
from
user"
rs1.CursorType
=
3
'
adOpenKeyset
rs1.LockType
=
3
'adLockOptimistic
rs1.Open
Do
While
Not
rs.Eof
rs1.AddNew
rs1(0)=j
for
i=0
to
rs.Fields.Count-1
rs1(i)=Trim(rs(i))
Next
rs1.Update
rs.MoveNext
j=j+1
Loop
rs.Close
rs1.Close
conn.Close
conn1.Close
Set
rs=nothing
Set
conn=nothing
⑵ 如何通过asp将excel表导入access数据库中
先导出,再导入
Excel导出函数
<%
Sub ExportToExcel
Response.ContentType = "application/vnd.ms-Excel"
Response.AddHeader "Content-Disposition", "attachment;Filename=Results.xls"
Response.Write "<body>"
Response.Write "<table border=1>"
Call WriteTableData
Response.Write "</table>"
Response.Write "</body>"
Response.Write "</html>"
End Sub
%>
Excel导入数据库
<%
dim FileName
FileName="Excel.xls" '取得文件名,来自项目经理的指定,路径固定在某个虚拟路径中
Dim conn, rs
set conn=CreateObject("ADODB.connection")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=" & Server.mappath(""&FileName&"") & ";" & _
"DefaultDir=G:\"
set rs=createobject("ADODB.recordset")
rs.Open "Select * from [Sheet1$]",conn, 2, 2
if rs.eof then
response.write "Excel表中无纪录"
else
set connDB = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("Excel.mdb")
'RESPONSE.WRITE DBpath
connDB.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set RsDB = Server.CreateObject("ADODB.Recordset")
SQLDB="Select * from Excel"
RsDB.open SQLDB,connDB,1,3
do while not rs.eof '利用循环读出数据
RsDB.addnew
RsDB("filename")=rs(0)
RsDB("id1")=rs(1)
RsDB("id2")=rs(2)
RsDB("id3")=rs(3)
RsDB("id4")=rs(4)
Rs.update
RsDB.movenext
rs.movenext
loop
'response.redirect FileName
end if
RsDB.movefirst
if RsDB.eof then
response.write "数据库中无记录"
else
do while not RsDB.EOF
response.write RsDB("filename")&" "
response.write RsDB("id1")&" "
response.write RsDB("id2")&" "
response.write RsDB("id3")&" "
response.write RsDB("id4")&" "
response.write "<br>"
RsDB.movenext
loop
end if
rs.close
set rs=nothing
set conn=nothing
%>
⑶ ASP代码中如何把EXCEL数据导入到SQL SERVER数据库中
'定义打开Excel表格的函数
Function OpenExcel(path)
dim excel,rs,strsql
On Error Resume Next
Set rs = Server.CreateObject("ADODB.RecordSet")
Set excel = Server.CreateObject("ADODB.Connection")
excel.Open "Driver={Microsoft Excel Driver (*.xls)};DBQ=" & path
If Err.number<> 0 Then
Response.Write "请检查上传的Excel文件内部格式,文件无法打开,导入失败!"
Response.End
End If
strsql = "SELECT * FROM [Sheet1$]" '在这里指定工作薄名称,默认是Sheet1$
Set rs = excel.Execute(strsql)
Set OpenExcel = rs
End Function
'读取文件中的内容
Dim rsInfo
Set rsInfo = Server.CreateObject("ADODB.RecordSet")
Set rsInfo = OpenExcel("E:/a.xls") '这里的文件路径请用Server.Path来获取
'检查读取结果
If rsInfo.State<> 1 Then
Response.Write "请检查Excel文件中的工作表命名是否为Sheet1,导入失败!"
Response.End
End If
If rsInfo.EOF And rsInfo.BOF Then
Response.Write "没有找到Excel表中的数据,导入失败!"
Response.End
End If
If IsNull(rsInfo.Fields(0)) or Trim(rsInfo.Fields(0))="" Then
Response.Write "没有找到Excel表中的数据,导入失败!"
Response.End
End If
'这里指定导入数据的列数,列数少了退出
If rsInfo.Fields.Count< 7 Then
Response.Write "Excel表中的数据列数不正确,导入失败!"
Response.End
End If
'创建数据库连接
dim dbrs,conn,sql
Set conn = Server.CreateObject("ADODB.Connection")
Set dbrs = Server.CreateObject("ADODB.Recordset")
'注: G_DB_ConnectString是连接数据库的字符串,自己定义
conn.ConnectionString = G_DB_ConnectString
conn.Open '打开数据库连接
'创建临时表
sql = "IF EXISTS (SELECT * FROM sysobjects WHERE xtype='U' and name='tmp_PartRes') "
sql = sql & "BEGIN Drop table tmp_PartRes END "
sql = sql & "Create table tmp_PartRes([ID] int identity(1,1),"
sql = sql & "PartID varchar(100),Brand varchar(100),[Package] varchar(100),"
sql = sql & "BatchNo varchar(100),[Price] varchar(100),[Stock] varchar(100) default('0'),"
sql = sql & "Brief varchar(100),StockFlag int default(1),"
sql = sql & "SuperFlag int default(1),SaleFlag int default(1))"
conn.execute sql
'取表结构 注意: 只取表的结构, 不要数据, 因为我这个是刚创建的临时表, 没有数据,
'如果表中存在数据, 要注意加上条件句, 防止取到数据 如: where ID = -1
sql = "SELECT * FROM tmp_PartRes"
dbrs.CursorLocation = 3 '这一定要设置为3
dbrs.Open sql,conn, 3, 4 '这里的参数必须是3和4
'取到表结构后, 必须要把活动连接及数据库连接关闭,这个很重要, 否则导入速度特慢.
Set dbrs.ActiveConnection = Nothing
conn.close
'提取Excel中的数据, 将excel中的数据放入到数据库表中.
While Not rsInfo.EOF
If Trim(rsInfo.Fields(0))<> "" Then
dbrs.AddNew
dbrs("PartID") = Ucase(Trim(rsInfo.Fields(0)))
dbrs("Brand") = Trim(rsInfo.Fields(1))
dbrs("Package") = Trim(rsInfo.Fields(2))
dbrs("BatchNo") = Trim(rsInfo.Fields(3))
dbrs("Price") = Trim(rsInfo.Fields(4))
If Trim(rsInfo.Fields(5))<>"" Then
dbrs("Stock") = Trim(rsInfo.Fields(5))
Else
dbrs("Stock") = "0"
End If
dbrs("Brief") = Trim(rsInfo.Fields(6))
End If
rsInfo.MoveNext
Wend
'更新记录集到数据库临时表
conn.Open '打开连接
dbrs.ActiveConnection = conn
dbrs.UpdateBatch '批量更新函数
'更新完成后, 关闭连接
dbrs.Close
Set dbrs = Nothing
rsInfo.Close
Set rsInfo = Nothing
⑷ Asp:Excel导入Access数据库
唉,这个问题之前不是答了你的吗?在原有的基础上改动少少就可以了的啊!我就更改了点地方再贴一次吧,你看看跟之前的有哪些地方不同! <% sUploadDir = "/" '---------------------------------------------------------------------- Dim oUpFileStream '---------------------------------------------------------------------- '文件上传类 Class UpFile_Class Dim Form,File,Version,Err Private Sub Class_Initialize Version = "无惧上传类 Version V1.2" Err = -1 End Sub Private Sub Class_Terminate '清除变量及对像 If Err < 0 Then Form.RemoveAll Set Form = Nothing File.RemoveAll Set File = Nothing oUpFileStream.Close Set oUpFileStream = Nothing End If End Sub Public Sub GetData (MaxSize) '定义变量 Dim RequestBinData,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName Dim iFindStart,iFindEnd Dim iFormStart,iFormEnd,sFormName '代码开始 If Request.TotalBytes < 1 Then '如果没有数据上传 Err = 1 Exit Sub End If If MaxSize > 0 Then '如果限制大小 If Request.TotalBytes > MaxSize Then Err = 2 '如果上传的数据超出限制 Exit Sub End If End If Set Form = Server.CreateObject ("Scripting.Dictionary") Form.CompareMode = 1 Set File = Server.CreateObject ("Scripting.Dictionary") File.CompareMode = 1 Set tStream = Server.CreateObject ("ADODB.Stream") Set oUpFileStream = Server.CreateObject ("ADODB.Stream") oUpFileStream.Type = 1 oUpFileStream.Mode = 3 oUpFileStream.Open oUpFileStream.Write Request.BinaryRead (Request.TotalBytes) oUpFileStream.Position = 0 RequestBinData = oUpFileStream.Read iFormEnd = oUpFileStream.Size bCrLf = ChrB (13) & ChrB (10) '取得每个项目之间的分隔符 sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1) iStart = LenB (sSpace) iFormStart = iStart+2 '分解项目 Do iInfoEnd = InStrB (iFormStart,RequestBinData,bCrLf & bCrLf)+3 tStream.Type = 1 tStream.Mode = 3 tStream.Open oUpFileStream.Position = iFormStart oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart tStream.Position = 0 tStream.Type = 2 tStream.CharSet = "gb2312" sInfo = tStream.ReadText '取得表单项目名称 iFormStart = InStrB (iInfoEnd,RequestBinData,sSpace)-1 iFindStart = InStr (22,sInfo,"name=""",1)+6 iFindEnd = InStr (iFindStart,sInfo,"""",1) sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) '如果是文件 If InStr (45,sInfo,"filename=""",1) > 0 Then Set oFileInfo = new FileInfo_Class '取得文件属性 iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10 iFindEnd = InStr (iFindStart,sInfo,"""",1) sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1) oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "\")) oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1) iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr (iFindStart,sInfo,vbCr) oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileStart = iInfoEnd oFileInfo.FileSize = iFormStart -iInfoEnd -2 oFileInfo.FormName = sFormName file.add sFormName,oFileInfo else '如果是表单项目 tStream.Close tStream.Type = 1 tStream.Mode = 3 tStream.Open oUpFileStream.Position = iInfoEnd oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2 tStream.Position = 0 tStream.Type = 2 tStream.CharSet = "gb2312" sFormValue = tStream.ReadText If Form.Exists (sFormName) Then Form (sFormName) = Form (sFormName) & ", " & sFormValue else form.Add sFormName,sFormValue End If End If tStream.Close iFormStart = iFormStart+iStart+2 '如果到文件尾了就退出 Loop Until (iFormStart+2) >= iFormEnd RequestBinData = "" Set tStream = Nothing End Sub End Class '---------------------------------------------------------------------------------------------------- '文件属性类 Class FileInfo_Class Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt '保存文件方法 Public Function SaveToFile (Path) On Error Resume Next Dim oFileStream Set oFileStream = CreateObject ("ADODB.Stream") oFileStream.Type = 1 oFileStream.Mode = 3 oFileStream.Open oUpFileStream.Position = FileStart oUpFileStream.CopyTo oFileStream,FileSize oFileStream.SaveToFile Path,2 oFileStream.Close Set oFileStream = Nothing End Function '取得文件数据 Public Function FileData oUpFileStream.Position = FileStart FileData = oUpFileStream.Read (FileSize) End Function End Class ' 检测扩展名的有效性 Sub CheckValidExt(sExt) Dim b, i, aExt b = False sAllowExt = "xls" aExt = Split(sAllowExt, "|") For i = 0 To UBound(aExt) If LCase(aExt(i)) = sExt Then b = True Exit For End If Next If b = False Then response.write("提示:请选择一个有效的文件,支持的格式有("+sAllowExt+")!<a href='javascript:history.back(1)'>返回</a>") Response.End End If End Sub ' 取随机文件名 Function GetRndFileName(sExt) Dim sRnd Randomize sRnd = Int(900 * Rnd) + 100 GetRndFileName = year(now) & month(now) & day(now) & hour(now) & minute(now) & second(now) & sRnd & "." & sExt End Function On Error Resume Next Dim oUpload, oFile ' 建立上传对象 Set oUpload = New upfile_class ' 取得上传数据,限制最大上传 oUpload.GetData(1024*1024) Submit = oUpload.Form("Submit") if Submit<>"" then If oUpload.Err > 0 Then Select Case oUpload.Err Case 1 'Call OutScript("parent.UploadError('请选择有效的上传文件!')") Case 2 Response.Write("你上传的文件总大小超出了最大限制!") Response.End End Select else Set oFile = oUpload.File("file") sFileExt = LCase(oFile.FileExt) sSaveFileName = "" if sFileExt<>"" then Call CheckValidExt(sFileExt) sOriginalFileName = oFile.FileName sSaveFileName = GetRndFileName(sFileExt) oFile.SaveToFile Server.Mappath(sUploadDir & sSaveFileName) end if end if end if %> <% sub exctoacc(excpath,mdbpath) Dim excConn,Coon 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 [Sheet1$]" '查询excel语句 excrs.Open excSql,excconn,2,2 set rs=server.createObject("ADODB.Recordset") Set conn=Server.CreateObject("ADODB.Connection") StrConn="provider=microsoft.jet.oledb.4.0; data source="&Server.MapPath(mdbpath) conn.Open StrConn sql="select * from client" rs.open sql,conn,1,3 do while Not excrs.EOF rs.addnew rs("name")=excrs("name") rs("age")=excrs("age") rs("address")=excrs("address") '........这里可以写更多的字段,注意的是ACCESS中的自编号ID不能更新赋值给它! rs.update excrs.MoveNext Loop rs.close set rs=nothing excrs.close set excrs=nothing excConn.close set excConn=nothing conn.close set conn=nothing response.write"数据导入成功!" End sub if sSaveFileName<>"" then call exctoacc(sSaveFileName,"Database/CLIENT.mdb") %>
⑸ 用.asp Excel、word内容导入数据库
word只能导入内容.excel才可以导入数据
这是段ASP代码,可以将excel数据导入
<%
dim conn '定义一个连接变量
dim conn2 '定义第二个连接变量
'On Error Resume Next
Server.ScriptTimeOut = 999999 '超时时间
set conn=CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source="&Server.MapPath("*.mdb") '要导入的Access数据库名称,这里是etwldbs.mdb
set conn2=CreateObject("ADODB.Connection")
conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 5.0;Data Source="&Server.MapPath("*.xls") '要导入的EXCEL表名称TEST.xls
'-----------------------------------------------------------------------------------------
'这里要说明的是,数据库和Excel表和该文件必须在网站同一目录里
'-----------------------------------------------------------------------------------------
sql = "Select * FROM [Sheet1$]" '要导入的Excel数据里面的表的名称,后面一定要加$
set rs = conn2.execute(sql)
do while not rs.eof
i=1
sql = "insert into haven([haven]) values('"& fixsql(rs(0)) &"')"
'其中的price是要导入的目标表,其后的company,fromhaven是price表中的字段名,但是要和后面的fixsql(rs(数字))要对应!
'response.write sql
'response.end
conn.execute(sql)
i=i+1
rs.movenext
Response.Write "<font face=宋体 size=2>正在插入 "&sql&"</font><Br>"
'在这里输出执行的语句,可以去掉的!
Response.Flush
loop
conn.close
set conn = nothing
conn2.close
set conn2 = Nothing
If Err = 0 Then
Response.Write "<script>alert('导入成功'),window.open('*.asp','_self')</script>"
Else
Response.Write "导入失败!"
End If
function fixsql(str)
dim newstr
newstr = str
if isnull(newstr) then
newstr = ""
else
newstr = replace(newstr,"’","’’")
end if
fixsql = newstr
end Function
%>
⑹ 怎样通过ASP代码把excel数据导入到数据库中去呀
这个不难,通过asp获取到xls的数据,然后再批量写入数据库。如果条件允许的话,可以直接在数据库上面导入xls文件数据。
⑺ 求助:用ASP将excel导入到数据库中
demo.asp
<%
Dim cn,oConn,connstr
'打开XLS.
Set cn = Server.CreateObject( "ADODB.Connection ")
cn.Provider = "Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source= " & Server.MapPath( "data.xls ") & "; " & _
"Extended Properties=Excel 8.0; "
cn.Open
'打开MDB.
connstr= "DBQ= "+server.MapPath( "data.mdb ")+ ";DefaultDir=;DRIVER=; "
set oConn=server.CreateObject( "ADODB.CONNECTION ")
oConn.open connstr
'读取数据.
set rsRead=server.CreateObject( "ADODB.Recordset ")
rsRead.Open "select * from [Sheet1$] ",cn,1,1
do until rsRead.EOF
'写入数据库.
oConn.Execute( "Insert into users(userid,password)Values( ' "& rsRead.Fields( "userid ")& " ', ' " &rsRead.Fields( "password ") & " ') " )
rsRead.MoveNext
loop
%>
数据库data.mdb
表users
id,uesrid,password
Excel文件data.xls
数据
userid password
12345 67890
'=====================ASP读取EXCEL注事项===========================
'i)将Excel97或Excel2000生成的XLS文件(book)看成一个数据库,其中的每一个工作表(sheet)看成数据库表
'ii)ADO假设Excel中的第一行为字段名.所以你定义的范围中必须要包括第一行的内容
'iii)Excel中的行标题(即字段名)不能够包含数字. Excel的驱动在遇到这种问题时就会出错的。例如你的行标题名为“F1”
'iiii)如果你的Excel电子表格中某一列同时包含了文本和数字的话,那么Excel的ODBC驱动将不能够正常, 处理这一行的数据类型,你必须要保证该列的数据类型一致
'===========================================================
代码都给全了 完全正确的代码 你还不满足?
有其他问题重新提问吧,
最后说下,
建议你重新安装ADO的驱动,MDAC的2.8版
也许是你没有注册ADO组件,
⑻ asp.net怎么样把excel文件导入到数据库和导出来(紧急求助+高分)
如果你只是要把excel保存到数据库,并不需要进一步的数据统计查询,你就可以简单地在asp.net的界面上放一个上传文件按钮,后台收到上传的excel文件,把它以二进制流的形式保存到SQL Server的Image字段或文件字段(据说sql2008才有)。导出时,在页面上放一个附件下载链接,用户点连接时你从数据库字段读出二进制流把它通过Response.OutputStream输出到页面上,即可出现excel的下载保存框。
如果你需要以导入的excel数据为基础,进行更多的数据统计查询,你就必须分析设计数据库表、字段,把相应的excel单元格数据保存到数据库字段。关键是如何从web页面导入excel单元格数据、又如何把查询出来的数据放到web页面上显示成客户需要的图表?
有两种方案:
1.用Excel自动化技术。
引用Excel的类型库生成.Net的包装类。导入时采用页面放上传文件按钮的方法,在服务器端收到文件后,用excel自动化类打开excel文件,再学会VBA语法,书写大量的代码读取单元格,然后连接数据库保存。导出时,查询数据库,启动excel自动化对象,通过VBA语法填写单元格,保存成excel文件,再用Response.OutputStream输出到页面上,触发excel文件的下载保存框。缺点:容易在服务器端产生excel死进程,代码编写复杂、代码量大、还要掌握VBA语法,用户需要上传、下载操作
有人会说,显示数据时可以用网页直接显示,不用导出成excel。其实也很麻烦:用网页显示复杂的报表格式,网页设计工作量大;如果客户要求导出excel,这个工作就省不了;如果客户要求打印、打印预览、页面设置,比起excel浏览器的打印就捉襟见肘了。
2.用微软Office中间件——SOAOffice。(建议使用最新版的)
用SOAOffice输出Excel,就不会再有上述烦恼。通过SOAOffice不仅能够动态填充excel,读取excel单元格,而且还能在浏览器里直接浏览excel、或者下载、另存。SOAOffice提供标准C#.Net组件,组件在服务器端不使用自动化调用,稳定支持大量web并发访问,这是用com调用无法实现的。组件的属性方法都比较简单,易于调用,你完全不用去掌握复杂的VBA调用。
由于是纯.Net组件,所以服务器端不需安装office。 SOAOffice的excel组件SOAExcel含有Sheet、Cell等类似Excel的简化接口,调用简单。SOAExcel不但能能把数据库字段值动态填充到Excel单元格,还能把用户输入的单元格的值提出给开发者保存到数据库。
SOAExcel能够在客户端浏览器的网页里通过SOAOffice直接显示生成的Excel,用户不必先下载再打开观看内容。
举个导出excel的例子:
SOAOfficeX.ExcelResponse SOAExcel = new SOAOfficeX.ExcelResponse();
SOAOfficeX.ExcelResSheet sheet1 = SOAExcel.openSheet("Sheet1"); // 打开一个Sheet
sheet1.openCell("D"+String.valueOf(8+i)).setValue(rs.getString("Count")); //循环填充数据。
SOAOfficeX.SOAOfficeCtrl SOACtrl = new SOAOfficeX.SOAOfficeCtrl(response);
SOACtrl.assign(SOAExcel); // 绑定数据
// 打开模板并生成最终的excel报表
SOACtrl.webOpen("doc/test.xls", 1, UserName, "Excel.Sheet");
上述代码不但动态填充生成excel,而且在网页里直接显示生成的Excel给终端用户,由于使用了1打开模式,Excel是只读显示的。
读取excel单元格的代码也很简单:
SOAOfficeX.ExcelRequest SOAExcel = new SOAOfficeX.ExcelRequest();
SOAOfficeX.IExcelReqSheet sheetOrder = SOAExcel.OpenSheet("销售订单");
SOAOfficeX.IExcelReqCell cell1;
cell1 = sheetOrder.OpenCell("I5");//订单编码
string sOrderNum = cell1.Value;//cell1.Value就是读取的结果
⑼ 如何将excel数据通过asp导入数据库
将excel数据通过asp导入数据库:
参考代码:
wenjian=request.Form("floor")
fileext=mid(wenjian,InStrRev(wenjian,".")+1)
if lcase(fileext)<>"xls" then
response.write "<script>alert ('文件格式不对,请上传Excel文件');window.location.href='updateFloor.asp';</script>"
response.end
end if
set conne=server.CreateObject("ADODB.Connection")
connStre="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( ""&wenjian&"" )&";Extended Properties='Excel 8.0;HDR=YES;IMEX=1';"
conne.open connStre
Sqle="select * from [sheet1$] "
Set rse = Server.CreateObject("ADODB.Recordset")
rse.open sqle,conne,1,1
'验证
hang=2
do while not rse.eof
'名称不能为空
if trim(rse(0))<>"" then
else
mess="第"& hang &"行名称为空,请检查!"
response.Write"<script>alert('"& mess &"').window.location.href='updateFloor.asp'</script>"
response.End()
end if
rse.movenext
hang=hang+1
loop
rse.movefirst
do while not rse.eof
set rst=server.CreateObject("adodb.recordset")
sqlt="select * from Sellman"
rst.open sqlt,conn,1,3
rst.addnew()
rst("CompanyName")=c2(rse(0))
rst("CompanyInfo")=c2(rse(1))
rst("address")=c2(rse(2))
rst("tel")=c2(rse(3))&" "&c2(rse(7))
rst("Fax")=c2(rse(4))
rst("linkman")=c2(rse(5))
rst("Homepage")=c2(rse(8))
rst("Email")=c2(rse(6))
rst.update()
rst.close
set rst=nothing
rse.movenext
loop
rse.close
set rse=nothing
response.Write "<script>alert('导入成功!');location.href='updateFloor.asp';</script>"