win32com Excel problem
Gabe Newcomb
Gabe.Newcomb at noetix.com
Wed May 22 18:43:01 EDT 2002
I'm still learning how to do this stuff myself, but here are some
thoughts:
1) this doesn't seem to be your problem, but be sure to be explicit
about the types of data you expect from each cell (I use str() and
int(), etc. when reading Cells.Value
2) more likely: perhaps this original spreadsheet has strangely
formatted columns? Just a stab in the dark.
3) be sure to kill any EXCEL tasks left open in taskmanager. This can
make access to the spreadsheet funky. I had to learn to add code to
close the spreadsheet in order to prevent leaving these open after
execution.
good luck! I hope this helps in some way
Gabe Newcomb
-----Original Message-----
From: Terje Johan Abrahamsen [mailto:terjeja at hotmail.com]
Sent: Wednesday, May 22, 2002 3:32 PM
To: python-list at python.org
Subject: win32com Excel problem
I am writing a little porgram that pulls out some info from a cell in
Excel.
It works great, excepy for when I try to pull out info from a
spreadsheet
that I want info from. Here is the code:
import win32com.client
import win32com.client.dynamic
from win32com.client import Dispatch
import sys
class accountcurrents:
xlApp = Dispatch("Excel.Application")
#ex = Dispatch("Extra.System")
xlApp.Visible = 1
xlApp.Workbooks.Add()
xlBook = xlApp.Workbooks(1)
xlSheet = xlApp.Sheets(1)
xlrad = 2
xlpol = "Donald"
xlamount = 1.00
xldato = "1/11/11"
def __init__(self):
print"Hello"
def finnxlpolicy(self):
accountcurrents.xlrad = accountcurrents.xlrad + 1
accountcurrents.xlpol =
accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value
if accountcurrents.xlpol == None :
print "yes"
else:
pass
If I have a blank spreadsheet, and fill in some values in the A collumn,
it
works great. However, when I use the spreadsheet that I actually want
the
info from, it all crashes. The spreadsheet I want the info from looks
like
this:
Policy# Effective Date Amount
MCK0259477 11/5/1998 240
MCK0278868 5/27/2001 -572.72
MCK0279107 1/14/2001 -1474.82
and so forth.
This errormessage comes:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Documents and Settings\dsporck\My
Documents\Python\accountcurrents\accountcurrents.py", line 23, in
finnxlpolicy
accountcurrents.xlpol =
accountcurrents.xlSheet.Cells(accountcurrents.xlrad,1).Value
File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line
347, in __getattr__
return apply(self._ApplyTypes_, args)
File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line
341, in _ApplyTypes_
return self._get_good_object_(apply(self._oleobj_.InvokeTypes,
(dispid,
0, wFlags, retType, argTypes) + args), user, resultCLSID)
com_error: (-2146827864, 'OLE error 0x800a01a8', None, None)
I use win2k, and newest version of Python, PythonWin and Win32Com. I do
not
change anything except for the contents of the spreadsheet. Even if I
just
copy the info into the spreadsheet that normally works.
Thanks in advance,
Terje
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list