【发布时间】:2019-01-31 11:31:41
【问题描述】:
我正在VB.Net 中创建一个 Excel 报告。报告创建成功,最后我终止了进程。但是当同一份报告同时从不同的机器上运行时,即它被多个用户使用时,它会杀死所有的进程并且只有一个用户能够创建报告。
您能否建议我如何在创建后仅关闭特定的 Excel 进程。下面是我的代码
If Not _xlApp.Workbooks Is Nothing Then
For Each wb In _xlApp.Workbooks
wb.Close(False)
Next
_xlApp.Workbooks.Close()
End If
_xlApp.DisplayAlerts = False
_xlApp.Quit()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
If _oSheet IsNot Nothing Then
Runtime.InteropServices.Marshal.ReleaseComObject(_oSheet)
End If
Runtime.InteropServices.Marshal.ReleaseComObject(_oBook)
_xlApp.Quit()
Runtime.InteropServices.Marshal.ReleaseComObject(_xlApp)
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
Dim proc As Diagnostics.Process
For Each proc In Diagnostics.Process.GetProcessesByName("EXCEL")
Try
proc.Kill()
Catch ex As Exception
End Try
Next
问题是我无法识别创建 excel 时应该关闭的进程的 PID。
【问题讨论】:
标签: asp.net vb.net excel-2010