2012-03-08 68 views
0

我試圖搜索一個代碼來更新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

回答

3

您的連接字符串不正確。

您有:

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

0

缺少一個分號此連接字符串的工作最適合我: -

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