當前位置:首頁 » 操作系統 » aspexcel導入到資料庫

aspexcel導入到資料庫

發布時間: 2022-04-20 19:05:08

⑴ 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>"

熱點內容
動態規劃01背包演算法 發布:2024-11-05 22:17:40 瀏覽:849
nasm編譯器如何安裝 發布:2024-11-05 22:01:13 瀏覽:180
登錄密碼在微信的哪裡 發布:2024-11-05 22:00:29 瀏覽:738
c防止反編譯工具 發布:2024-11-05 21:56:14 瀏覽:247
安卓虛擬機怎麼用 發布:2024-11-05 21:52:48 瀏覽:343
php時間搜索 發布:2024-11-05 20:58:36 瀏覽:478
燕山大學編譯原理期末考試題 發布:2024-11-05 20:13:54 瀏覽:527
華為電腦出現臨時伺服器 發布:2024-11-05 20:05:08 瀏覽:408
斗戰神免費挖礦腳本 發布:2024-11-05 19:53:25 瀏覽:665
網吧伺服器分別是什麼 發布:2024-11-05 19:45:32 瀏覽:392