Hey folks...
Newbie here. I'm working with win32com launching, closing and
re-launching Excel grabbing output and doing stuff.
Well, on some occasions, I get the following error:
Traceback (most recent call last):
File "checkrates.py" , line 95, in ?
newdata = getNewData(test cases1)
File "checkrates.py" , line 62, in getNewData
excel.Workbooks .Open(docdir + 'TOSrat2006_09. xls')
File "C:\Python24\li b\site-packages\win32c om\client\dynam ic.py", line
496, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: Excel.Applicati on.Workbooks
Sometimes the code runs fine. Sometimes I get this error. The code in
question is:
import string
from win32com.client import Dispatch
docdir = 'E:\\scripts\\P ython\\RSAutoma tion\\'
def getOldData(test cases):
#open excel
excel = Dispatch("Excel .Application")
excel.Workbooks .Open(docdir + 'TOSrat2006_07. xls')
oldoutputlist = []
for rsinput in testcases.xread lines():
inputlist = string.split(rs input, ',')
# iterate through and update spreadheet input
cellx = range(3,51)
values = range(0,48)
for i,r in zip(cellx, values):
excel.ActiveShe et.Cells(i,2).V alue = inputlist[r]
#read spreadsheet output and cat to outputlist
premium = excel.ActiveShe et.Cells(32,6). Value
oldoutputlist.a ppend(premium)
# close up excel
excel.ActiveWor kbook.Close(Sav eChanges=0)
excel.Quit()
del excel
return oldoutputlist
def getNewData(test cases):
# open excel
excel = Dispatch("Excel .Application")
excel.Workbooks .Open(docdir + 'TOSrat2006_09. xls')
newoutputlist = []
for rsinput in testcases.xread lines():
inputlist = string.split(rs input, ',')
# iterate through and update spreadsheet input
cellx = range(3,51)
values = range(0,48)
for i,r in zip(cellx, values):
excel.ActiveShe et.Cells(i,2).V alue = inputlist[r]
# read ratesheet output and cat to outputlist
premium = excel.ActiveShe et.Cells(32,6). Value
newoutputlist.a ppend(premium)
excel.ActiveWor kbook.Close(Sav eChanges=0)
excel.Quit()
del excel
return newoutputlist
if __name__ == "__main__":
testcases = open('arse_test cases.csv','r')
testcases1 = open('arse_test cases.csv','r')
olddata = getOldData(test cases)
newdata = getNewData(test cases1)
print olddata
print newdata
It seems like Python or COM is having a hard time freeing up (or
closing down) excel prior to the "getNewData " function running and it
is stepping on itself. I thought the stuff I'm doing at the end of
getOldData should successfully shut down excel.
Any advice, criticism, flames are appreciated.
Cheers! 1 5531
You could try using DispatchEx to make sure you always
get a new instance of Excel.
Roger
"Ransom" <gy***@sbcgloba l.net> wrote in message news:11******** **************@ f6g2000cwb.goog legroups.com... Hey folks...
Newbie here. I'm working with win32com launching, closing and re-launching Excel grabbing output and doing stuff.
Well, on some occasions, I get the following error:
Traceback (most recent call last): File "checkrates.py" , line 95, in ? newdata = getNewData(test cases1) File "checkrates.py" , line 62, in getNewData excel.Workbooks .Open(docdir + 'TOSrat2006_09. xls') File "C:\Python24\li b\site-packages\win32c om\client\dynam ic.py", line 496, in __getattr__ raise AttributeError, "%s.%s" % (self._username _, attr) AttributeError: Excel.Applicati on.Workbooks
Sometimes the code runs fine. Sometimes I get this error. The code in question is:
import string from win32com.client import Dispatch docdir = 'E:\\scripts\\P ython\\RSAutoma tion\\'
def getOldData(test cases): #open excel excel = Dispatch("Excel .Application") excel.Workbooks .Open(docdir + 'TOSrat2006_07. xls')
oldoutputlist = [] for rsinput in testcases.xread lines():
inputlist = string.split(rs input, ',')
# iterate through and update spreadheet input cellx = range(3,51) values = range(0,48) for i,r in zip(cellx, values):
excel.ActiveShe et.Cells(i,2).V alue = inputlist[r]
#read spreadsheet output and cat to outputlist premium = excel.ActiveShe et.Cells(32,6). Value oldoutputlist.a ppend(premium) # close up excel excel.ActiveWor kbook.Close(Sav eChanges=0) excel.Quit() del excel return oldoutputlist
def getNewData(test cases): # open excel excel = Dispatch("Excel .Application") excel.Workbooks .Open(docdir + 'TOSrat2006_09. xls') newoutputlist = [] for rsinput in testcases.xread lines():
inputlist = string.split(rs input, ',')
# iterate through and update spreadsheet input cellx = range(3,51) values = range(0,48) for i,r in zip(cellx, values):
excel.ActiveShe et.Cells(i,2).V alue = inputlist[r]
# read ratesheet output and cat to outputlist premium = excel.ActiveShe et.Cells(32,6). Value newoutputlist.a ppend(premium) excel.ActiveWor kbook.Close(Sav eChanges=0) excel.Quit() del excel return newoutputlist
if __name__ == "__main__": testcases = open('arse_test cases.csv','r') testcases1 = open('arse_test cases.csv','r') olddata = getOldData(test cases) newdata = getNewData(test cases1)
print olddata print newdata
It seems like Python or COM is having a hard time freeing up (or closing down) excel prior to the "getNewData " function running and it is stepping on itself. I thought the stuff I'm doing at the end of getOldData should successfully shut down excel.
Any advice, criticism, flames are appreciated.
Cheers!
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =--- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Justin Stockton |
last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and
I'm running into an issue importing the win32com.client module.
Before installing the new version, I made sure to properly remove old
version (as well as the mx libraries I had installed). I then
installed the new version as a user with the Administrator role. I
know I'm technically not supposed to install to a directory with a
space in the name, but it worked fine for...
|
by: Cristian Hasbun from Chile |
last post by:
I need a win32com guru please...
i'm not python expert, but i understand mi trouble...
Requirements:
Hook EyesWeb 3.2.0 (http://www.eyesweb.org) COM Module with Python
2.0.1
i used win32com libraries and generate an early binding for module
(using prog_id)
|
by: goermezer |
last post by:
Hello,
I have some problems to automate a CAD (computer aided design) Software called
CATIA V5 from Dassault Systemes.
CATIA V5 has a builtin VB-Editor like Word, Excel, … and registers itself as a
COM-server. With VB one can automate everything in CATIA V5 with a lot of
registered Object Libraries.
A VB example:
|
by: g.franzkowiak |
last post by:
I'm trying to use a proprietary windows software with COM and win32com.
The result is everytime the error message
com_error: (-2147418113, 'Catastrophic failure', None, None)
I've read this in some e-mails, but can't find the solution and I have
not enough experience with Windows and COM.
Can anybody help ?
|
by: ago |
last post by:
I am trying to make the win32com HelloWorld server work with a VBA
client but I get:
Run-time error '-2147467259(80004005)':
Automation error
Unspecified error
I googled for the error but the suggested solutions (commenting out
_reg_class_spec_ and putting the server on the python path) do not seem
to make any difference (to be precise, unless I comment out
| |
by: mirandacascade |
last post by:
O/S : Win2K
vsn of Python: 2.4
Hoping to find information that provide information about error
messages being encountered.
Pythonwin session:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
|
by: SPJ |
last post by:
Sorry, forgot to mention Subject in my earlier post, hence reposting.
------------
I am writing a script which need's to convert an excel file to csv (text) format. For that I am using the following code:
excel = win32com.client.Dispatch("Excel.Application","Quit")
workbook = excel.Workbooks.Open(xlsfile)
workbook.SaveAs(csvfile, FileFormat=24) # 24 represents xlCSVMSDOS
workbook.Close(False)
excel.Quit()
|
by: Bill Davy |
last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers
from my address book which is an Excel spreadsheet to my mobile phone. I
came across the following snippet of code which enabled me to the contacts
at least list. I had to root around to discover CdoDefaultFolderContacts
(though it was guessable; how could I enumerate win32com.client.constants?).
I now want to work through the Contacts in Outlook patching in...
|
by: RyanN |
last post by:
Greetings,
I'm trying to get DispatchWithEvents() to work with HyperAccess
(terminal program) without much success. I've done a bunch of
searching and found some examples using IE:
This works but doesn't handle the "Event Driven Functions":
haObj = win32com.client.Dispatch(r"HAWin32")
And so does this Internet Explorer Example:
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |