2014-03-13 429 views
0

我希望能夠在讀取和寫入數據的Excel文件經典ASP

C:\Inetpub\wwwroot\excel\excel.xls 

我用下面的代碼試圖讀取和寫入使用經典ASP存儲在我的本地機器上的Excel文件:

<% 
' Set Connection Params 
Set oConn = Server.CreateObject("ADODB.connection") 
oConn.Open "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790;" &_ 
"DBQ=c:\Inetpub\wwwroot\excel\excel.xls;" &_ 
"DefaultDir = C:\Inetpub\wwwroot\excel\" 

Set RS=Server.CreateObject("ADODB.recordset") 

' Write the SQL Query 
RS.open "SELECT * FROM my_range", oConn 

do until RS.EOF 
Response.Write (RS("NAME") & " -- " & RS("EMAIL") & "") 
RS.movenext 
Loop 

'Close the recordset/connection 

RS.Close 
oConn.Close 
Set RS = Nothing 
%> 

這是我從here

了,但我得到了以下錯誤:

Microsoft OLE DB Provider for ODBC Drivers error '80004005' 

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 

/ASP/excel.asp, line 4 

我只是一個ASP初學者,不知道該怎麼做。請幫幫忙!

回答

0
  1. 您的服務器是64位機器。如果是,您可能需要確保您的應用程序池,32個應用程序

  2. 你可以嘗試連接字符串中的一個位置。 http://www.connectionstrings.com/microsoft-jet-ole-db-4-0/

如果你的MS Access的副本,我建議您導入Excel電子表格導入Access數據庫,並連接到。直接使用Excel作爲數據源可能會很痛苦。