EXL = CreateObject("Excel.Application")
Try
EXL = GetObject(, "Excel.Application")
Catch ex As Exception
If EXL Is Nothing Then
EXL = New Excel.Application
End If
End Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
worksheets=null
worksheet=null
excelApp=null
range=null
把操作Excel文件用到的对象实例全部释放。然后资源回收!
GC.Collect()