电脑里一直开着一个空白的excel进程,我对比了一下,写入速度会快很多啊。RENHQ版主,你也帮忙给给建议吧?是不是想办法让一个excel进程一直存在?
If HMIRuntime.Tags("记录").Read Then
Set ExcelApp = GetObject(,"Excel.Application")
ExcelApp.DisplayAlerts = False
ExcelApp.WorkBooks.Close
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(Filename_string) Then
''今天生成的文件存在
Set ExcelBook = ExcelApp.Workbooks.Open(Filename_string)
Set ExcelSheet = ExcelBook.Sheets.Item("Sheet1")
ExcelApp.DisplayAlerts = False
下面的变量a,b计算过程省略
ExcelSheet.Cells( a, b).Value = HMIRuntime.tags("本次下料重量").Read
ExcelBook.Save
ExcelBook.Close
原来在这个地方有个:ExcelApp.Quit,现在删掉观察的。
Set ExcelBook = Nothing
Set ExcelApp = Nothing
Else
''今天生成的文件不存在
Set ExcelBook = ExcelApp.Workbooks.Open("C:\空白.xlsx")
Set ExcelSheet = ExcelBook.Sheets.Item("Sheet1")
ExcelApp.DisplayAlerts = False
ExcelSheet.Cells(1, 1).Value = HMIRuntime.tags("本次下料重量").Read
ExcelBook.Saveas (Filename_string)
ExcelBook.Close
原来在这个地方有个:ExcelApp.Quit,现在删掉观察的。
Set ExcelBook = Nothing
Set ExcelApp = Nothing
End If
HMIRuntime.Tags("记录").Write 0
End If