help ...Excel object not closing

G

Guest

Hi
I am writing an application using VB.NET and office 2003.
I write some data into the Excel sheet using automation
and then close it but, I can still see the excel.exe
running in the task manager. .Please help me...:((

The code I am using is :
Private Sub openreport()

Dim table As DataTable = CType
(dgresults.DataSource, DataSet).Tables(0)
Dim colIndex As Int32
Dim rowIndex As Int32
Dim row As DataRow
Dim col As DataColumn

Try
If Not (m_oExcelApp Is Nothing) Then
CloseReportTemplate()
End If

m_oExcelApp = New Excel.ApplicationClass
m_oExcelApp.Visible = False
m_oBooks = m_oExcelApp.Workbooks

m_oBook = m_oBooks.Open("d:\documents\Bol.xlt")

m_oSheet = m_oBook.Worksheets(1)

rowIndex = rowIndex + 2
For Each row In table.Rows

rowIndex = rowIndex + 1
colIndex = 0
For Each col In table.Columns

colIndex = colIndex + 1
m_oExcelApp.Cells(rowIndex, colIndex)
= row(col.ColumnName).ToString()
Next
Next
m_oBook.SaveAs("c:\test.xls")

' m_oExcelApp.Workbooks.Close()
Catch exc As Exception
Response.Write(exc.Message)

Finally

CloseReportTemplate()
End Try

End Sub
Private Sub CloseReportTemplate()

If Not (m_oBook Is Nothing) Then
m_oBook.Close(True)
End If

If Not (m_oSheet Is Nothing) Then

System.Runtime.InteropServices.Marshal.ReleaseComObject
(m_oSheet)
m_oSheet = Nothing
End If

If Not (m_oBook Is Nothing) Then

System.Runtime.InteropServices.Marshal.ReleaseComObject
(m_oBook)
m_oBook = Nothing
End If

If Not (m_oBooks Is Nothing) Then

System.Runtime.InteropServices.Marshal.ReleaseComObject
(m_oBooks)
m_oBooks = Nothing
End If

If Not (m_oExcelApp Is Nothing) Then
m_oExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject
(m_oExcelApp)
m_oExcelApp = Nothing
End If
End Sub


vishal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top