如何读取EXCEL的数据,如何往EXCEL写数据
最佳答案
给你一个参考程序:
Dim objExcelApp,oWorkBook
Dim TH_GC_E
Dim ZF_GC_S
Dim GC_NO
Dim iBlankLine
Dim DateTime
Dim Path
Set TH_GC_E=HMIRuntime.Tags("TH_GC_E")
TH_GC_E.Read
Set Path=HMIRuntime.Tags("Path")
Path.Read
If TH_GC_E.Value=0 Then
MsgBox "QQQQQQQQQ",,"QQQQ"
Exit Sub
End If
Set ZF_GC_S=HMIRuntime.Tags("ZF_GC_S")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DateTime=Mid(Date(),1)+" "+Mid(Time(),1)
''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = False 'True
Set oWorkBook = objExcelApp.Workbooks.Open(""&Path.VAlue&"")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
iBlankLine=objExcelApp.Cells(1,4).Value+1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If objExcelApp.Cells(iBlankLine,1).Value="" Then
oWorkBook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
MsgBox "ssCCCCCCCCC",,"sss"
Exit Sub
End If
If CLng(Mid(objExcelApp.Cells(iBlankLine,1).Value,5))<>TH_GC_E.Value Then
MsgBox "ssssssssss",,"sss"
oWorkBook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
Exit Sub
End If
If objExcelApp.Cells(iBlankLine,3).Value <>"" Then
'iBlankLine=oWorkBook.ActiveSheet.Columns(1).Find("").Row
'MsgBox iBlankLine
objExcelApp.Cells(iBlankLine,4).Value =DateTime 'ScreenItems("tag3").OutputValue
objExcelApp.Cells(1,4).Value=objExcelApp.Cells(1,4).Value+1
Else
MsgBox "CCCCCCCCCCCCC",,"CCCC"
End If
oWorkBook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ZF_GC_S.Value=TH_GC_E.Value
ZF_GC_S.Write()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MsgBox "111111111111",,"1111"
提问者对于答案的评价:
谢谢帮助
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc270318.html