Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 9th, 2006, 03:50 AM
Registered User
Join Date: Oct 2006
Location: kalyan, maharshtra, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Remove Excel Object From Memory

Hi Guys,
Can u help me to solve this query.
My problem is I am not able to kill Excel object from Memory.
I have used every thing to remove this object. but No code is Working
For destroy purpose I have used.

System.Runtime.InteropServices.Marshal.ReleaseComO bject

But this all efforts are not working.

Can anyone able to told me that is it possible to kill EXCEL.EXE from Memory.

See My Code:

oXL = new Excel.ApplicationClass();
                    oXL.Visible = false;
// oWB = oXL.ExcelConnection.Workbooks.Add(Missing.Value);
// worksheet1 = (Worksheet)oWB.ActiveSheet;
// r = worksheet1.get_Range("A1","A1");
// r.Value = txtTarget.Text;
// r1 = worksheet1.get_Range("B1","B1");
// r1.Value = txtAchivement.Text;
// r2 = worksheet1.get_Range("C1","C1");
// r2.Value = txtFormula.Text;

                    //Get a new workbook.

                    oWB = oXL.Workbooks.Add(Missing.Value);
                    worksheet1 = (Worksheet)oWB.ActiveSheet;
                    r = worksheet1.get_Range("A1","A1");

                    r.Value = txtTarget.Text;

                    r1 = worksheet1.get_Range("B1","B1");
                    r1.Value = txtAchivement.Text;

                    r2 = worksheet1.get_Range("C1","C1");
                    r2.Value = txtFormula.Text;

oWB.SaveAs(@"D:\Temp\"+strFile,Excel.XlFileFormat. xlWorkbookNormal,
                        null,null,false,false,Excel.XlSaveAsAccessMode.xlS hared,false,false,null,null);
                    int i= 0;


System.Runtime.InteropServices.Marshal.ReleaseComO bject (r);
                    System.Runtime.InteropServices.Marshal.ReleaseComO bject (r1);
                    System.Runtime.InteropServices.Marshal.ReleaseComO bject (r2);
                    System.Runtime.InteropServices.Marshal.ReleaseComO bject (oXL);
                    System.Runtime.InteropServices.Marshal.ReleaseComO bject(worksheet1);

worksheet1 = null;
oWB = null;
oXL = null;

Jatin s. Patel
  #2 (permalink)  
Old October 11th, 2006, 07:44 AM
Registered User
Join Date: Oct 2006
Location: kalyan, maharshtra, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I have find out solution for this type of problem.
After 2 days hard work & RND I got Success to Solve this problem.
But the problem is this code will RUN only in VB.net not In ASP.net
I m still Searching solutions for that.

I m uploading My code. Hope It will give help to some one who need to perform such type of functionality.


++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Developed By : Jatin Patel
contact No : 9819376788
VB.net Code
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++

Declarations :

Imports Excel
Imports System
Imports System.Reflection
Imports System.IO
Imports System.Runtime.InteropServices

 Public Function OpenExcel(ByVal Interact As Boolean) As Excel.ApplicationClass

        Dim App As Excel.ApplicationClass
        App = New Excel.ApplicationClass
        App.DisplayAlerts = Interact
        App.Interactive = Interact
        App.Visible = Interact
        ' uniquely mark this instance of Excel
        App.Caption = System.Guid.NewGuid.ToString.ToUpper
        Return App
 End Function

 Public Sub Main1()
        Dim myExcel As Excel.ApplicationClass
        Dim sh As Excel.Worksheet
        myExcel = OpenExcel(True)
        sh = myExcel.Workbooks.Add().ActiveSheet
        sh.Range("A1:A1").Value = "Hello World"
        Console.WriteLine("... hit ENTER to close:")
        CloseExcel(myExcel, True)
        Console.WriteLine("... hit ENTER to exit:")

    End Sub

Private Sub CloseExcel(ByVal App As Excel.ApplicationClass, ByVal bl As Boolean)

        If Not App.Workbooks Is Nothing Then
            Dim wb As Excel.Workbook
            Dim ws As Excel.Worksheet
            For Each wb In App.Workbooks
                For Each ws In wb.Worksheets
                    System.Runtime.InteropServices.Marshal.ReleaseComO bject(ws)
                    ws = Nothing
                System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb)
                wb = Nothing
        End If
        App.DisplayAlerts = False
    End Sub

Sub KillAllExcels()
        Dim proc As System.Diagnostics.Process
        For Each proc In System.Diagnostics.Process.GetProcessesByName("EXC EL")
 End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

************************************************** *************

Hope it will Help You.. If you find some solution to run this code in ASP.net then please contact me.

Jatin s. Patel
  #3 (permalink)  
Old May 30th, 2007, 03:53 PM
Registered User
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Jatin, have you found a solution to this yet? I am running into the same problem with Excel.

Thanks in advance

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Application is left in Memory, why??? thetwai C# 3 March 29th, 2007 11:19 AM
EXCEL process stays in memory even after deallocat kool_creative General .NET 0 January 13th, 2006 05:04 AM
Finding Memory Occupied By a Object satishkumarj VB Components 3 December 10th, 2004 03:58 PM
excel export giving memory error msrnivas .NET Web Services 0 September 6th, 2004 12:09 AM

All times are GMT -4. The time now is 12:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.