问题描述
我有一个程序可以打开一些 excel 文件来检查值然后关闭它们。 源文件位于网络上。 一切正常,我可以读取值,但随着时间的推移,我遇到了一些性能问题,有时需要 10 多秒才能打开它们并读取值。 我看到它创建了很多没有数据的临时文件(0Ko)。当我删除所有临时文件时,时间回到不到一秒。
这是源代码:
Private Shared Sub Verification(listLots As List(Of String) )
Dim AppliExcel As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application()
For Each numLot As String In listLots
Dim nomFichier As String = GetCheminFichier(numLot)
If System.IO.File.Exists(nomFichier) Then
Dim Classeur As Workbook = nothing
Dim Feuille As Worksheet
'free all existing workbook
For Each wb As Workbook In AppliExcel.Workbooks
wb.Close(SaveChanges:=False)
ReleaseExcelObject(wb)
Next
'Open excel file
Classeur = AppliExcel.Workbooks.Open(nomFichier,True)
......
Classeur.Close(False)
ReleaseExcelObject(Classeur)
Classeur = nothing
end if
Next
AppliExcel.Quit()
ReleaseExcelObject(AppliExcel)
End Sub
Private Shared Sub ReleaseExcelObject(obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = nothing
Catch ex As Exception
obj = nothing
Finally
GC.Collect()
End Try
End Sub
我想知道问题出在哪里以及如何解决。
希望有人有想法。 亲切的问候 数控。
解决方法
这是一个错误,而不是一个功能,所以没有唯一正确的解决方案。
禁用所有防病毒软件。如果可行,请从 AV 中排除文件夹,从 AV 中排除文件类型。
如果这不起作用:
更改 Excel 临时文件的位置。
尝试为客户端和服务器使用不同版本的 Windows。
禁用自动保存和自动恢复。
禁用远程差分压缩
还有很多其他因素可能会导致此类问题 - 同步设置、隐私(报告)设置、Windows 资源管理器更新设置、缩略图更新设置......从 AV 开始,看看你会得到什么。