pythonexcelcomrtd

Excel RTD server in Python not updating data


I've got the excelRTDserver.py up and running in Excel 2010 (32bit) by changing the EXCEL_TLB_MINOR value to 7. I can see the server in the add-ins list and if I enter =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the current time. But it never updates. If I change the "5" to another number, I get an update but after the initial change it never changes again.

How do I get it to update? I found someone else with a similar problem here, but no solution.

UPDATE: I've got a little further - there is an exception raised within ServerStart when casting the PyIDispatch callback object into a IRTDUpdateEvent callback object. Using this method to capture the error message, I get "Cannot create a file when that file already exists.". If I follow the suggestion here and use win32com.client.CastTo(CallbackObject,'IRTDUpdateEvent') I get "This COM object can not automate the makepy process - please run makepy manually for this object", but I have already run makepy for Microsoft Excel 12.0 Object Library (1.6).

Any help would be greatly appreciated.


Solution

  • I think you may be out of luck.

    According to the author of excelRTDServer.py in a recent python-win32 thread:

    The message that this is in response to describes your exact problem, and it's recent, so maybe you already got this info directly, but in case you didn't...

    I fear that things with IRTDUpdateEvent have changed with recent versions of excel (since Excel 2007? I guess that's not so 'recent' anymore...).

    While hunting around for news of interface changes, I came across this thread in a java forum:

    http://www.nevaobject.com/phpbb3/viewtopic.php?t=516

    The part that worries me is this comment:

    "Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don't really know whether it is a bug in Excel 12 or a feature."

    So far I haven't been able to confirm this against the MSDN information... But if this is true, it does explain the problem being seen. Many older examples on the web, and pywin32+makepy treat this interface as IDispatch, and wrap it accordingly.

    I don't think we can fix this with pywin32 as it is right now. My understanding is that it relies on IDispatch support. May need to look at comtypes (http://starship.python.net/crew/theller/comtypes/) to wrap the (new?) IRTDUpdateEvent objects, or maybe a C extension. :(