excel - VB.Net Excel 临时文件性能问题
问题描述
我有一个程序可以打开一些 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
我想知道问题出在哪里以及如何解决。
希望有人有想法。亲切的问候NC。
解决方案
这是一个错误,而不是一个功能,所以没有一个正确的解决方案。
禁用所有防病毒软件。如果可行,请从 AV 中排除文件夹,从 AV 中排除文件类型。
如果这不起作用:
更改 excel 临时文件的位置。
尝试为客户端和服务器使用不同版本的 Windows。
禁用自动保存和自动恢复。
禁用远程差分压缩
还有一大堆可能导致此类问题的其他事情 - 同步设置、隐私(报告)设置、Windows Explorer 更新设置、缩略图更新设置......从 AV 开始,看看你在哪里。
推荐阅读
- angular - 在文件夹内创建角度库
- java - 无法使用 IBM JDK 1.8 建立 https 连接。它确实适用于 oracle JDK1.8
- reactjs - Material-ui 如何切换 Menu 组件点击 IconButton
- amazon-web-services - 如何从 Ubuntu Server 获取 CodeCommit 存储库
- sql - 在 FULL OUTER JOIN 中计算 DISTINCT
- python - 如何将系列传递给 Pandas 数据框中的布尔函数?
- php - 如何在字符串中找到这种格式的日期?
- excel - excel vba在另一个工作表中定义和输入范围内的数据
- css - Safari 切断按钮内元素的框阴影
- powershell - 当 PowerShell 脚本出错时如何发送电子邮件通知?