473,686 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

closing excel application

When I close an excel application opened from a python program with .Close()
methood , in tasks manager is still present 'excel.exe' process and if I
open manually an excel applicaion I have a transparent excel window... my os
is win 2000 pro... Which is the right way to close an excel applicatio from
python?
Thanks
Jul 18 '05 #1
4 21102
"federico" <ma********@hot mail.com> writes:
When I close an excel application opened from a python program with .Close()
methood , in tasks manager is still present 'excel.exe' process and if I

[...]

There was a thread here about this just two weeks ago. Google
(Groups) for it.
John
Jul 18 '05 #2
"federico" <ma********@hot mail.com> wrote in message news:<bm******* ***@lacerta.tis calinet.it>...
When I close an excel application opened from a python program with .Close()
methood , in tasks manager is still present 'excel.exe' process and if I
open manually an excel applicaion I have a transparent excel window... my os
is win 2000 pro... Which is the right way to close an excel applicatio from
python?
Thanks


The "right way" would be:

import win32com.client
import pythoncom
app = win32com.client .Dispatch('Exce l.Application')
app.Visible = 1
....
print pythoncom._GetI nterfaceCount()
app = None
print pythoncom._GetI nterfaceCount()
pythoncom.CoUni nitialize()

Pythoncom holds and manages the reference count. Which, you cannot
tweak with. (At least that's the intention of Mark Hammond... you
don't have access to the Release() method of the IUnknown interface.)
Therefore, ideally, you should catch all exceptions in your program,
and exit your Python program gracefully and invoke the
CoUninitialize( ) method to release all references to COM objects. That
is, your program is should not fail due to unhandled exceptions...
otherwise you will have dangling reference to COM objects, which you
cannot recover in new sessions of Python.

But the world is never ideal. :)

Here are a few "solutions" . I hope others can contribute more.

(1) Simply kill the dangling Excel by hand from the task manager.
(2) Really, really, really make sure you use exception handling in
your program, and always exit your program gracefully by invoking
pythoncom.CoUni ntialize().
(3) Find out the process id, and kill the dangling process before
anything else. The windows APIs provided by Mark Hammand may allow
this, but I have used instead the tlist.exe and kill.exe executables
from outside Python (you can launch them using os.system() or some
other ways of executing system command. I remember having problems
with Windows 98, though, some piping issues, but after adding one more
little file it was solved.)
(4) Write yourself a little COM program in C/C++ to invoke the
Release() method of the IUnknown() interface. You might even be able
to do this from using Thomas Heller's ctypes module without actually
programming in C/C++. I never tried it, though.

Of course the "right way" is alternative (2). I'd like to hear other
people's solutions.

--------------------

The Dispatch() late binding method is deceivingly easy to use, but
once you start to use it, you will realize that there are a lot of
issues. Using COM programming this way is best limited to simple,
routine tasks. Of course, that's just my opinion.

Hung Jung
Jul 18 '05 #3
hu********@yaho o.com (Hung Jung Lu) wrote in message

import win32com.client
import pythoncom
app = win32com.client .Dispatch('Exce l.Application')
app.Visible = 1
...
print pythoncom._GetI nterfaceCount()
app = None
print pythoncom._GetI nterfaceCount()
pythoncom.CoUni nitialize()


Sorry, missed the line app.Quit() before the first print statement.

import win32com.client
import pythoncom
app = win32com.client .Dispatch('Exce l.Application')
app.Visible = 1
....
app.Quit()
print pythoncom._GetI nterfaceCount()
app = None
print pythoncom._GetI nterfaceCount()
pythoncom.CoUni nitialize()

Hung Jung
Jul 18 '05 #4
Thanks a lot for your answer

"Hung Jung Lu" <hu********@yah oo.com> ha scritto nel messaggio
news:8e******** *************** **@posting.goog le.com...
hu********@yaho o.com (Hung Jung Lu) wrote in message

import win32com.client
import pythoncom
app = win32com.client .Dispatch('Exce l.Application')
app.Visible = 1
...
print pythoncom._GetI nterfaceCount()
app = None
print pythoncom._GetI nterfaceCount()
pythoncom.CoUni nitialize()


Sorry, missed the line app.Quit() before the first print statement.

import win32com.client
import pythoncom
app = win32com.client .Dispatch('Exce l.Application')
app.Visible = 1
...
app.Quit()
print pythoncom._GetI nterfaceCount()
app = None
print pythoncom._GetI nterfaceCount()
pythoncom.CoUni nitialize()

Hung Jung

Jul 18 '05 #5

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

Similar topics

2
402
by: Mark | last post by:
Hi all, as many had, i have some problems terminating the excel-process. I implemented the solutions i found in this forums. Tried most combinations of them ;-). It still doesn't work. I'll post my code-snippets below. I hope u can shine some light on the solution.
2
2266
by: Atley | last post by:
I have written an application that exports data from SQL to Excel. It all works perfectly except that if you open the Task Manager after running my application, there is an instance of Excel in the list for each time the extract has been run. I cannot seem to find anything on this, I have the application closing properly as far as I can see, but it is staying in the process table and the only way to get rid of it is to either reboot...
0
1284
by: Sania | last post by:
Hi, We have an application that create an excel object on the very beginning of the application: objExcel = New Excel.Application Then I am passing the excel reference to the one of forms that on the button click event creates workbook, sheet, fills sheet with data and gives the control to the user.
7
2445
by: rdemyan via AccessMonster.com | last post by:
I want to make sure that I'm closing an opened spreadsheet correctly. I've been having some locking up problems. The following code adds a dummy row to the spreadsheet to ensure that that the data gets transferred in the correct format. It seems to be working correctly, but if anyone has any comments on that I'd appreciate it. Right now, I'm mostly concerned about opening and closing the spreadsheet. Here's the pertinent part of the code: ...
1
1699
by: John Bailo | last post by:
I wrote a c# web service that creates an Excel spreadsheet. Even though I follow all the formal procedures for closing the app and finalizing, an instance of Excel still remains in memory. I follow the procedures described here: http://blogs.geekdojo.net/richardhsu/archive/2003/11/14/281.aspx Yet, excel.exe stays there with IUSR_ as the owner.
6
24018
by: pleaseexplaintome_2 | last post by:
Help please. The excel instance is removed from task manager when I run the code below. If I uncomment the lines pertaining to a workbook, the instance of excel is not removed from task manager. can someone help? Thanks Excel.Application xl1 = new Excel.Application(); //Microsoft.Office.Interop.Excel.Workbook wb1 = xl1.Workbooks.Add(System.Reflection.Missing.Value); xl1.Visible = true; xl1.Quit();
4
9899
by: Yoduh | last post by:
Hello, I'm fairly new to javascript. I'm making a website for my personal use that will read from Excel and display some data on an HTML page and I've been learning javascript as I go. A problem I have is when I leave the website running overnight (it refreshes itself every minute), an error eventually pops up that says "Not enough memory to run Microsoft Office Excel. Please close other applications and try again." Internet Explorer...
1
4183
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int tmpX = 0; int indexRow = 1; int indexCol = 1; int existingPIDs;
2
3046
by: Ronin85 | last post by:
Hi , I recently have much pain working with excel application especially closing excel . I try several method but with no success i try to urge garbage collector to dispose excel application object, I tried to kill excel process but i find it difficult to figure out which is the right process to kill .It is out of question to kill all process on the server so i have to find out which is the proper one bit I can't retrieve the id of the process...
2
3956
by: Silgd1 | last post by:
Hi All.... I'm using python 2.4, Win XP Pro v.2002 sp3, and I use pyscripter 1.9.9.2 as my editor. I have written code to open an existing excel file and grab some data. The problem I am having is closing down the excel application. Here some "bits" of the code I am using: xlApp = Dispatch("Excel.Application") xlApp.Workbooks.Open(Filename = path+fname)
0
8584
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9054
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6440
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2945
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.