简体   繁体   English

读取和写入数据 Excel 文件 Classic ASP

[英]Reading and Writing Data Excel File Classic ASP

I want to be able to read from and write to an excel file using Classic ASP stored in my local machine at我希望能够使用存储在本地计算机中的 Classic ASP 读取和写入 excel 文件

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

I tried using the following code:我尝试使用以下代码:

<% 
' 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 
%> 

Which I got from here我从这里得到的

But I got the following error:但我收到以下错误:

    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

I'm just a beginner with ASP and not sure what to do.我只是 ASP 的初学者,不知道该怎么做。 Please help out!请帮忙!

  1. Is your server a 64 bit machine.你的服务器是 64 位机器吗? If it is you may need to enable 32 bit applications in your application pool如果是,您可能需要在应用程序池中启用 32 位应用程序

  2. You could try one of the connection strings here.您可以尝试此处的连接字符串之一。 http://www.connectionstrings.com/microsoft-jet-ole-db-4-0/ http://www.connectionstrings.com/microsoft-jet-ole-db-4-0/

If you have a copy of MS Access I recommend that you import your excel spreadsheet into an Access database and connect to that.如果您有 MS Access 的副本,我建议您将 Excel 电子表格导入 Access 数据库并连接到该数据库。 Using excel directly as a datasource can be painful.直接使用 excel 作为数据源可能会很痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM