[Tutor] Excel com strange behavior

johan nilsson johanpo at googlemail.com
Fri Aug 29 14:18:23 CEST 2008


Dear all,

I have a problem with talking to Excel. Somehow the command Workbooks.Add()
gives me problems?
If I open a workbook in Excel, then I get the trace back below. I can not
say that I quite understand why this does not work. Any insights would be
highly appreciated.

If I "manually" open the workbook, I can fill the data in the sheet

Johan


>>> from win32com.client import Dispatch
>>> xlApp = Dispatch("Excel.Application")
>>> xlApp.Visible = 1
>>> xlApp.Workbooks.Add()

Traceback (most recent call last):
  File "<pyshell#67>", line 1, in <module>
    xlApp.Workbooks.Add()
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\dynamic.py",
line 467, in __getattr__
    if self._olerepr_.mapFuncs.has_key(attr): return
self._make_method_(attr)
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\dynamic.py",
line 295, in _make_method_
    methodCodeList =
self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0)
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py",
line 297, in MakeFuncMethod
    return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py",
line 318, in MakeDispatchFuncMethod
    s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc, names,
defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):'
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py",
line 604, in BuildCallList
    argName = MakePublicAttributeName(argName)
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py",
line 542, in MakePublicAttributeName
    return filter( lambda char: char in valid_identifier_chars, className)
  File
"c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py",
line 542, in <lambda>
    return filter( lambda char: char in valid_identifier_chars, className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080829/9a2dd971/attachment.htm>


More information about the Tutor mailing list