Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I create excel file from asp.net - how to remove Excel.exe from memory

Status
Not open for further replies.

Plato2

Programmer
Dec 6, 2002
192
US
I'm creating excel from asp.net and it creates Excel.exe in memory. How can I get rid of it?

Dim oXL As Excel.Application
Dim oWB As Excel._Workbook
Dim oSheet As Excel._Worksheet

GC.Collect() ' clean up any other excel guys hangin' around...
oXL = New Excel.Application
oXL.Visible = False
'Get a new workbook.
oWB = oXL.Workbooks.Add
'new work sheet
oSheet = oWB.Worksheets.Add
oSheet.Range("A4").Value = "GOOD"

oXL.Visible = False
oXL.UserControl = False
Dim strFileName As String = "report.xls"
oWB.SaveAs(strCurrentDir + strFileName)
' Need all following code to clean up and extingush all references!!!

oWB.Close(Nothing, Nothing, Nothing)
oXL.Workbooks.Close()
oXL.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB)
oSheet = Nothing
oWB = Nothing
oXL = Nothing
GC.Collect() ' force final cleanup!
 
Try this

fIsProcessRunning("excel", True)




Public Function fIsProcessRunning(ByVal proc As String, ByVal endprocess As Boolean) As Boolean

'Ends Excel process
Dim tmpproc As Process()
Dim x As Integer = 0
Try
'Attemp to get process by name
tmpproc = System.Diagnostics.Process.GetProcessesByName(proc)

'Check length to determine if a process was found
If tmpproc.Length >= 1 Then
If endprocess Then
'cycle through all processes and kill them
For x = 0 To tmpproc.Length - 1
Try
tmpproc(x).Kill()
Catch exs As Exception
MsgBox("An error occurred while trying to kill the processes." & vbCrLf & _
exs.ToString)
strError = exs.ToString
strError = strError & " in Function fIsProcessRunning"
WriteToErrorLog(strError)
Return False
End Try
Next
End If
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.ToString)
strError = ex.ToString
strError = strError & " in Function fIsProcessRunning"
WriteToErrorLog(strError)
Return False
End Try

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top