更新Excel工作表(在经典的ASP/Vbscript中)

更新Excel工作表(在经典的ASP/Vbscript中)

问题描述:

我试图搜索一个代码来更新Classic-ASP中的Excel(XLS)文件,但是我无法让它工作。更新Excel工作表(在经典的ASP/Vbscript中)

这里是我有:

<!--#include file="../adovbs.inc"--> 
<% 
' Open and Update and then Close The XLS File 
Dim objConn 
set objConn = Server.CreateObject("ADODB.Connection") 
Dim FLConnect 
Dim strSQLexcel 

' Create the connection string. 
    FLConnect = "Provider=Microsoft.Jet.OLEDB.4.0 Data Source=" & Server.MapPath("TEST.xls") & "Extended Properties='Excel 8.0;HDR=No'" 

' Create the SQL statement. 
    strSQLexcel= "UPDATE [Sheet1$A1:A1] SET F1='TestValue1'" 

set objConn = Server.CreateObject("ADODB.Recordset") 

'Set objConn = New ADODB.Connection 

' Create and open the Connection object. 
    objConn.Open FLConnect 

' Execute the insert statement. 
    objConn.Execute strSQLexcel 

' Close and destroy the Connection object. 
    objConn.Close 

%> 

但我不断收到一个错误说:“该连接无法用于执行此操作正是在这样的背景下关闭或无效的。”

非常感谢您...

+2

尝试与失踪; - ... xls“)&”Ext .. - ... xls“)& ";分机.. – 2012-03-08 16:26:27

您的连接字符串不正确。

您有:

Provider=Microsoft.Jet.OLEDB.4.0 Data Source=" 
& Server.MapPath("TEST.xls") & "Extended Properties='Excel 8.0;HDR=No'" 

你是4.0之后和在扩展

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" 
& Server.MapPath("TEST.xls") & ";Extended Properties='Excel 8.0;HDR=No'" 

http://connectionstrings.com

+0

我将其更改为:FLConnect =”Provider = Microsoft.Jet.OLEDB.4.0; Data Source =“&Server.MapPath (“TEST.xls”)&“Extended Properties ='Excel 8.0; HDR =没有'” 但仍然是相同的错误!:-( – compcobalt 2012-03-08 16:44:50

+0

感谢您的网站,我现在将看看它。 – compcobalt 2012-03-08 16:48:29

缺少一个分号此连接字符串的工作最适合我: -

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myExcel.xlsm;Extended Properties='Excel 12.0 Macro;HDR=YES';