wincc里设置一个查询按钮,通过vbs脚本从SQL server数据库 中查询数据存储到excel中,调用excel显示。可是excel能调出来,但是excel里却没有数据。请问该怎么办呢?是不是wincc和excel之间需要什么设置呢?一下是我的vbs脚本的内容:
Dim sCon
Dim sSql
Dim oRs
Dim conn
Dim oCom
Dim Con
Dim data7
Dim objExcelApp
data7=HMIRuntime.tags("编号").read
‘连接数据库
Con="Provider=MSDASQL;DSN=Zhuguan;UID=fmy;PWD=123;"
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = Con
conn.CursorLocation = 3
conn.Open
sSql="SELECT * FROM FMY WHERE 编号=‘"&data7&"‘;"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandType = 1
oCom.CommandText = sSql
Set oRs = oCom.Execute
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible= True
objExcelApp.Workbooks.open"F:\report.xlsx"
objExcelApp.sheet(1).Cells(3,0).Value = oRs.Fields(0).Value
objExcelApp.sheet(1).Cells(3,1).Value = oRs.Fields(1).Value
objExcelApp.sheet(1).Cells(3,2).Value = oRs.Fields(2).Value
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp=Nothing
Set oRs = Nothing
conn.Close
Set conn = Nothing
End Sub