473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

COM Question (Excel)

Dear All,

I have create an excel (COM Object) using this code

Excel.Application xls = new Excel.Application();

but I can not remove it from memory although I have using close and quit

wb.Close(false, false, 0);
xls.Quit();
If I open task manager there is excel.exe. If I run multiple time the number
of excel.exe in task manager will increase.

Please Help.

Regards,
Gunawan
Feb 2 '07 #1
6 2047
In article <uB**************@TK2MSFTNGP06.phx.gbl>,
jg**********@gmail.com says...
Dear All,

I have create an excel (COM Object) using this code

Excel.Application xls = new Excel.Application();

but I can not remove it from memory although I have using close and quit

wb.Close(false, false, 0);
xls.Quit();
If I open task manager there is excel.exe. If I run multiple time the number
of excel.exe in task manager will increase.
What is "wb"? A reference to a workbook I assume?

Make sure you release every COM object you get a reference to using
Marshal.ReleaseComObject()

Excel.Application xls = new Excel.Application();
try
{
wb = ...
try
{
...
}
finally
{
wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);
}
}
finally
{
xls.Quit();
Marshal.ReleaseComObject(xls);
}

--
Patrick Steele
http://weblogs.asp.net/psteele
Feb 2 '07 #2
Hi Patrick,
I still can not release excel.exe from the memory.

Currenty I am using this code on *.aspx file to response click button.

Is it related to this issue? and I am using visual studio 2003.
Marshal.ReleaseComObject still can not remove excel.exe. :(
Regards,
Gunawan
"Patrick Steele" <pa*****@mvps.orgwrote in message
news:MP************************@msnews.microsoft.c om...
In article <uB**************@TK2MSFTNGP06.phx.gbl>,
jg**********@gmail.com says...
>Dear All,

I have create an excel (COM Object) using this code

Excel.Application xls = new Excel.Application();

but I can not remove it from memory although I have using close and quit

wb.Close(false, false, 0);
xls.Quit();
If I open task manager there is excel.exe. If I run multiple time the
number
of excel.exe in task manager will increase.

What is "wb"? A reference to a workbook I assume?

Make sure you release every COM object you get a reference to using
Marshal.ReleaseComObject()

Excel.Application xls = new Excel.Application();
try
{
wb = ...
try
{
...
}
finally
{
wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);
}
}
finally
{
xls.Quit();
Marshal.ReleaseComObject(xls);
}

--
Patrick Steele
http://weblogs.asp.net/psteele

Feb 2 '07 #3
It's more likely that whatever you are doing in Excel is leaving something
open. Are you doing OLE Automation or what? This is a problem *many* people
have when doing OLE Automation with Excel.

For example, I had a problem once and it turned out to be a problem with
Ranges. If you use any kind of Ranges (like
..range(.cells(1,2),.cells(3,4)).merge=true), Excel creates a Range object
behind the scenes, and does not dispose of it. You have to do this:

(Sorry this is VB)

Dim myRange as Range = xlsheet.range(.Cells(1,2),.cells(3,4))
myRange.Merge=True
myRange = Nothing

That's just one example, but it depends on what you're doing. The way I
tracked it down was I commented out every single excel command I was using,
then uncommented them one at a time until I found the culprit. Tedious, but
effective.

So the question is, what are you doing with Excel? Are you just opening it
and closing it, or are you doing something in-between?

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Gunawan" <jg**********@gmail.comwrote in message
news:uw*************@TK2MSFTNGP06.phx.gbl...
Hi Patrick,
I still can not release excel.exe from the memory.

Currenty I am using this code on *.aspx file to response click button.

Is it related to this issue? and I am using visual studio 2003.
Marshal.ReleaseComObject still can not remove excel.exe. :(
Regards,
Gunawan
"Patrick Steele" <pa*****@mvps.orgwrote in message
news:MP************************@msnews.microsoft.c om...
>In article <uB**************@TK2MSFTNGP06.phx.gbl>,
jg**********@gmail.com says...
>>Dear All,

I have create an excel (COM Object) using this code

Excel.Application xls = new Excel.Application();

but I can not remove it from memory although I have using close and
quit

wb.Close(false, false, 0);
xls.Quit();
If I open task manager there is excel.exe. If I run multiple time the
number
of excel.exe in task manager will increase.

What is "wb"? A reference to a workbook I assume?

Make sure you release every COM object you get a reference to using
Marshal.ReleaseComObject()

Excel.Application xls = new Excel.Application();
try
{
wb = ...
try
{
...
}
finally
{
wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);
}
}
finally
{
xls.Quit();
Marshal.ReleaseComObject(xls);
}

--
Patrick Steele
http://weblogs.asp.net/psteele


Feb 2 '07 #4
I will try to explain what I am doing with excel file.

I try to open excel file
Open Excel file
---------------
Application xls = new Application();
_Workbook wb = xls.Workbooks.Open(strFilename,
0, true, 5, "", "", true, Excel.XlPlatform.xlWindows,
"\t", false, false, 0 , true, 0, 0);

_Worksheet wsh = (_Worksheet) wb.Worksheets[1];

Retrieving Data
for
{

strKodeBarang = ((Range) wsh.Cells[i,1]).Value2.ToString() ;
strNamaBarang = ((Range) wsh.Cells[i,2]).Value2.ToString() ;
}
Releasing Object
-----------------
Marshal.ReleaseComObject(wsh);

wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);

xls.Quit();
Marshal.ReleaseComObject(xls);
I use this tehnique using vb6 and no excel.exe retain on memory.
But using C# always left excel.exe in memory.

Regards,
Gun

"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:HO******************************@comcast.com. ..
It's more likely that whatever you are doing in Excel is leaving something
open. Are you doing OLE Automation or what? This is a problem *many*
people have when doing OLE Automation with Excel.

For example, I had a problem once and it turned out to be a problem with
Ranges. If you use any kind of Ranges (like
.range(.cells(1,2),.cells(3,4)).merge=true), Excel creates a Range object
behind the scenes, and does not dispose of it. You have to do this:

(Sorry this is VB)

Dim myRange as Range = xlsheet.range(.Cells(1,2),.cells(3,4))
myRange.Merge=True
myRange = Nothing

That's just one example, but it depends on what you're doing. The way I
tracked it down was I commented out every single excel command I was
using, then uncommented them one at a time until I found the culprit.
Tedious, but effective.

So the question is, what are you doing with Excel? Are you just opening it
and closing it, or are you doing something in-between?

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Gunawan" <jg**********@gmail.comwrote in message
news:uw*************@TK2MSFTNGP06.phx.gbl...
>Hi Patrick,
I still can not release excel.exe from the memory.

Currenty I am using this code on *.aspx file to response click button.

Is it related to this issue? and I am using visual studio 2003.
Marshal.ReleaseComObject still can not remove excel.exe. :(
Regards,
Gunawan
"Patrick Steele" <pa*****@mvps.orgwrote in message
news:MP************************@msnews.microsoft. com...
>>In article <uB**************@TK2MSFTNGP06.phx.gbl>,
jg**********@gmail.com says...
Dear All,

I have create an excel (COM Object) using this code

Excel.Application xls = new Excel.Application();

but I can not remove it from memory although I have using close and
quit

wb.Close(false, false, 0);
xls.Quit();
If I open task manager there is excel.exe. If I run multiple time the
number
of excel.exe in task manager will increase.

What is "wb"? A reference to a workbook I assume?

Make sure you release every COM object you get a reference to using
Marshal.ReleaseComObject()

Excel.Application xls = new Excel.Application();
try
{
wb = ...
try
{
...
}
finally
{
wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);
}
}
finally
{
xls.Quit();
Marshal.ReleaseComObject(xls);
}

--
Patrick Steele
http://weblogs.asp.net/psteele



Feb 2 '07 #5
Hi,

Gunawan wrote:
Hi Patrick,
I still can not release excel.exe from the memory.

Currenty I am using this code on *.aspx file to response click button.
That's quite a bad idea, regardless of all the other problems you're
getting:

http://support.microsoft.com/default...US;q257757#kb2

There are other ways to deal with Excel on the server. Using ADO.NET ist
a good way, or you can also manipulate Excel files in XML format.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 2 '07 #6
"Gunawan" <jg**********@gmail.comwrote in message
news:eZ**************@TK2MSFTNGP03.phx.gbl...
>I will try to explain what I am doing with excel file.

I try to open excel file
Open Excel file
---------------
Application xls = new Application();
_Workbook wb = xls.Workbooks.Open(strFilename,
0, true, 5, "", "", true, Excel.XlPlatform.xlWindows,
"\t", false, false, 0 , true, 0, 0);

_Worksheet wsh = (_Worksheet) wb.Worksheets[1];

Retrieving Data
for
{

strKodeBarang = ((Range) wsh.Cells[i,1]).Value2.ToString() ;
strNamaBarang = ((Range) wsh.Cells[i,2]).Value2.ToString() ;
}
Releasing Object
-----------------
Marshal.ReleaseComObject(wsh);

wb.Close(false, false, 0);
Marshal.ReleaseComObject(wb);

Should be...
xls.Quit();
GC.Collect();
GC.WaitForPendingFinalizers();

Anyway, you should know that this is an unsupported scenario for Office application,
especially in .NET as you can never rely on the Finalizer to release all outstanding COM
references.

http://support.microsoft.com/kb/257757

Willy.

Feb 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.