LibreOffice - How to create a file dialog via python macro? -
i'd know if it's possible create standard file dialog save pdf via python macro. i've tried write code based on outdated documentation: wiki.openoffice.org libreoffice crashes after execution:
import os import uno import sys import traceback com.sun.star.ui.dialogs.templatedescription import filesave_simple def file_dialog(): try: octx = uno.getcomponentcontext() oservicemanager = octx.getservicemanager() ofilepicker = oservicemanager.createinstancewithargumentsandcontext( 'com.sun.star.ui.dialogs.filepicker', (filesave_simple,), octx ) ofilepicker.title = 'export as' #odisp = ofilepicker.text ofilepicker.execute() except: pass #odisp = traceback.format_exc(sys.exc_info()[2]) at end need pass selected path write document, odisp = ofilepicker.text returns: (<type 'exceptions.attributeerror'>. there way set file type?
does have experience it?
i used xray on ofilepicker object. there couple of interesting methods called setcurrentfilter , appendfiltergroup. based on names, might used filter file types visible. unfortunately i'm not sure how use them.
also xray, determined text not method or property of ofilepicker object. i'm not sure code snippet trying there? if retrieve filepath, 1) needs done after .execute , 2) selected filepath stored array of strings, path has pulled out of array. of work in openoffice in starbasic; below working example in basic of printing filepath selected user:
sub testfilepicker ofilepickerdlg = createunoservice( "com.sun.star.ui.dialogs.filepicker" ) ofilepickerdlg.settitle("my test title") if ofilepickerdlg.execute() > 0 print convertfromurl(ofilepickerdlg.files(0)) end if end sub
Comments
Post a Comment