I am using OpenOffice 4.01 and python 3.4 running on Windows 8.1.
- Code: Select all Expand viewCollapse view
import os
import win32com.client
dl = 'CDEFGHIJKLMNOPQRSTUVWXYZ'
drives = ['%s:' % d for d in dl if os.path.exists('%s:' % d)]
for d in drives:
if os.path.isdir(d+'\\Scheduler'):
DriveOption = d
default_drivepath =DriveOption+"\\Scheduler\\"
norm_drivepath = DriveOption+'/Scheduler/'
outfile = 'o_f_ScheduledEvents.csv'
OF_file = 'schedule.ods'
URLout = 'file:///'+norm_drivepath+outfile
sURL = 'file:///'+norm_drivepath+OF_file
sPath = default_drivepath+OF_file
manager = win32com.client.Dispatch("com.sun.star.ServiceManager")
desktop = manager.createInstance("com.sun.star.frame.Desktop")
manager._FlagAsMethod("Bridge_GetStruct") #used later to set propertyValues
args = []
doc1 = desktop.loadComponentFromURL(sURL,"Scheduler",0,args)
sheets1 = doc1.getSheets()
ws = sheets1.getByName('Schedule')
we = sheets1.getByName('EventStream')
#next two lines do not work as they do in a macro
#oListener = CreateUnoListener( "docListener_","com.sun.star.document.XDocumentEventListener" )
#doc1.addDocumentEventListener(oListener)
#above line produces error: not defined
# The below does not work either
docListener = manager.createInstance("com.sun.star.document.XDocumentEventListener")
doc1.addDocumentEventListener(docListener_)
#above line fails with this error:
#Traceback (most recent call last):...
#doc1.addDocumentEventListener(docListener_)
# File "<COMObject <unknown>>", line 2, in addDocumentEventListener
#pywintypes.com_error: (-2147352567, 'Exception occurred.', (1001, '[automation bridge] ', 'InterfaceOleWrapper_Impl::Invoke : \n[automation #bridge]UnoConversionUtilities<T>::createOleObjectWrapper \nThe VARIANT does not contain an object type! ', None, 0, 0), None)
#same type error as above with this variation
doc1.addDocumentEventListener("docListener_")
while docListener_documentEventOccured(o):
if obe[0] == "OnSave":
print('Doc registered save')