EXCEL进程无法退出,网上找的代码都不行,急急急急急急急急急急急急急急急急急急急急急急!!!
我写了一个类库,关于编辑EXCEL文档的方法,但是同样的一个函数在form上调用完后任务管理器中(调试出了方法后)没有EXCEL进程驻留,但是WEB上调用后任务管理器中(同样的断点)EXCEL进程还在,百思不得其解,请高手帮忙看一下代码,代码如下:
Imports System
Imports System.Text
Imports System.Collections
Imports System.IO
Imports System.DiagnosticsImports Microsoft.Office.Interop
Public Class ExcelPrint
Public Sub New(ByVal strPath As String)
path = strPath
End Sub
Public Function print111()
Dim xl, xlx As Object
Dim xlbook As Object
Dim pApp, i As Integer
xl = CreateObject("Excel.Application")
xl.Visible = False
'With xl
pApp = System.GC.GetGeneration(xl)
Dim file As String
file = path & "\aaa.xls"
xlbook = xl.Workbooks.Add(file)
Dim xlsheet As Object
xlbook.Sheets(1).Activate()
xlsheet = xlbook.activesheet
For i = 1 To 10
xlsheet.Cells(2, i) = i.ToString()
Next
'删除文件代码略,我每次运行都把目录下的aaa1.xls文件手动删除
xlbook.SaveAs(path & "\aaa1.xls")
xlsheet = Nothing
xlbook.Close()
'xl.Quit()
xlbook = Nothing
If Not xl Is Nothing Then
xl.Quit()
xl = Nothing
End If
'End With
System.GC.Collect(pApp)
End Function
End Class
web调用代码:ExcelPrint excelPrint=new ExcelPrint(Page.MapPath("")+@"\..");
excelPrint.print111();
Form调用代码:ExcelPrint excelPrint=new ExcelPrint(Application.StartupPath);
excelPrint.print111();