Creating a new workbook in Excel from Python breaks

Posted by Marcelo Cantos on Stack Overflow See other posts from Stack Overflow or by Marcelo Cantos
Published on 2010-05-14T02:19:51Z Indexed on 2010/05/14 2:24 UTC
Read the original article Hit count: 411

Filed under:

I am trying to use the stock standard win32com approach to drive Excel 2007 from Python. However, when I try to create a new workbook, things go pear-shaped:

Python 2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit (Intel)] on win32
...
>>> import win32com.client
>>> excel = win32com.client.Dispatch("Excel.Application")
>>> wb = excel.Workbooks.Add()

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    wb = excel.Workbooks.Add()
  File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 467, in __getattr__
    if self._olerepr_.mapFuncs.has_key(attr): return self._make_method_(attr)
  File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 295, in _make_method_
    methodCodeList = self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0)
  File "C:\Python26\lib\site-packages\win32com\client\build.py", line 297, in MakeFuncMethod
    return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File "C:\Python26\lib\site-packages\win32com\client\build.py", line 318, in MakeDispatchFuncMethod
    s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):'
  File "C:\Python26\lib\site-packages\win32com\client\build.py", line 604, in BuildCallList
    argName = MakePublicAttributeName(argName)
  File "C:\Python26\lib\site-packages\win32com\client\build.py", line 542, in MakePublicAttributeName
    return filter( lambda char: char in valid_identifier_chars, className)
  File "C:\Python26\lib\site-packages\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)
>>> 

What is going wrong here? Have I done something silly, or is Python/win32com/Excel somehow broken?

© Stack Overflow or respective owner

Related posts about python