Hi guys, I have a strange problem. I wrote some python code to open a brand new calc document and upon opening the spreadsheet, some Xmodifylisteners are registered to monitor the changing values of some cells. It works in my Windows and raspberrypi Linux OSs, but failed in my Mac laptop. I thought it may have something to do with my code so I decided to try this example python macro Monitoring Document Events and followed the guidance of this post How to get save listener event to python code - #3 by Nancy2510 by issuing the following command:
soffice ‘vnd.sun.star.script:test2.py$OnLoad?language=Python&location=user’ test.ods
test2.py is the name I saved for the example code and put in the right folder. Obviously the file was found and executed but still failed with the following message:
com.sun.star.uno.RuntimeException: Error during invoking function OnLoad in module file:///Users/edwinli/Library/Application%20Support/LibreOffice/4/user/Scripts/python/test2.py (<class ‘AttributeError’>: ‘NoneType’ object has no attribute ‘addDocumentEventListener’
File “/Applications/LibreOffice.app/Contents/Resources/pythonscript.py”, line 915, in invoke
ret = self.func( *args )
File “/Users/edwinli/Library/Application Support/LibreOffice/4/user/Scripts/python/test2.py”, line 62, in OnLoad
listener = UiDocument() # Initiates listening
File “/Users/edwinli/Library/Application Support/LibreOffice/4/user/Scripts/python/test2.py”, line 26, in init
self.listen() # Start monitoring doc. events
File “/Users/edwinli/Library/Application Support/LibreOffice/4/user/Scripts/python/test2.py”, line 41, in listen
self.doc.addDocumentEventListener(self)
)
I wonder what I did wrong? Any help is greatly appreciated. Thanks in advance.
(By the way, if I just run the macro from the opened spreadsheet it has no problem.)
Ed