Newbie: Win32 COM problem

Discussion in 'Python' started by Paul Hemans, Aug 25, 2010.

  1. Paul Hemans

    Paul Hemans Guest

    Simple class to wrap the xlwt module for COM access

    pyXLS.py:

    from xlwt import Workbook

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

    def __init__(self):
    self.book = None

    def createBook(self):
    self.book = Workbook()

    def createSheet(self,sheetName):
    self.book.add_sheet(sheetName)

    def writeSheetCell(self, sheet, row, col, value, style=""):
    sheet = self.book.get_sheet(sheet)
    sheet.write(row,col,value,style)

    def saveBook(self,fileName):
    self.book.save(fileName)

    if __name__=='__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(WrapXLS)

    It registers ok with --debug. Code executing within Foxpro (no comments
    pls):
    oPyXLS = CREATEOBJECT("PyXLS.Write")
    oPyXLS.createBook()
    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\dispatcher.py", line
    47, in _Invoke_
    return self.policy._Invoke_(dispid, lcid, wFlags, args)
    File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 277,
    in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
    File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 282,
    in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
    File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 585,
    in _invokeex_
    return func(*args)
    File "C:\development\PyXLS\pyXLS.py", line 13, in createSheet
    def createBook(self):
    AttributeError: WrapXLS instance has no attribute '_book'
    pythoncom error: Python error invoking COM method.

    Can anyone help?
     
    Paul Hemans, Aug 25, 2010
    #1
    1. Advertisements

  2. Paul Hemans

    Mark Hammond Guest

    That line seems an unlikely source of the error. Note that as win32com
    uses an in-process model by default, your problem may be that you
    changed your implementation but didn't restart the hosting process - and
    therefore are still using an earlier implementation.

    HTH,

    Mark
     
    Mark Hammond, Aug 26, 2010
    #2
    1. Advertisements

  3. Paul Hemans

    Paul Hemans Guest

    Yes, that was it. I just needed to restart the host process.
    Thanks
     
    Paul Hemans, Aug 26, 2010
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.