Newbie: Win32 COM problem

Paul Hemans darwin at
Wed Aug 25 14:33:21 CEST 2010

Simple class to wrap the xlwt module for COM access

from xlwt import Workbook

class WrapXLS:
    _reg_clsid_ = "{c94df6f0-b001-11df-8d63-00e09103a9a0}"
    _reg_desc_ = "XLwt wrapper"
    _reg_progid_ = "PyXLS.Write"
    _public_methods_ = 
    # _public_attrs_ = ['book']

    def __init__(self): = None

    def createBook(self): = Workbook()

    def createSheet(self,sheetName):

    def writeSheetCell(self, sheet, row, col, value, style=""):
        sheet =

    def saveBook(self,fileName):

if __name__=='__main__':
    import win32com.server.register

It registers ok with --debug. Code executing within Foxpro (no comments 
oPyXLS.createSheet("Sheet 1")    -- Error here

Output in Python Trace Collector (PythonWin):
in _GetIDsOfNames_ with '(u'createsheet',)' and '1033'

in _Invoke_ with 1001 1033 3 (u'Sheet 1',)
Traceback (most recent call last):
  File "C:\Python26\lib\site-packages\win32com\server\", line 
47, in _Invoke_
    return self.policy._Invoke_(dispid, lcid, wFlags, args)
  File "C:\Python26\lib\site-packages\win32com\server\", line 277, 
in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Python26\lib\site-packages\win32com\server\", line 282, 
in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Python26\lib\site-packages\win32com\server\", line 585, 
in _invokeex_
    return func(*args)
  File "C:\development\PyXLS\", line 13, in createSheet
    def createBook(self):
AttributeError: WrapXLS instance has no attribute '_book'
pythoncom error: Python error invoking COM method.

Can anyone help? 

More information about the Python-list mailing list