The issue of this python macro will need to take one .txt with questions and answers file and then to save it into a fillable PDF.
My problem come when I try to create the .doc under LibreOffice ( not WriteDocument – LibreOficeWriter) with python macro.
This python macro will be add to new toolbar + new macro to LibreOffice default window.
I try with this source code:
import os
import uno
import sys
import traceback
# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size
from com.sun.star.lang import XMain
# try to open and save
from com.sun.star.ui.dialogs.TemplateDescription import FILEOPEN_SIMPLE
from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE
def file_dialog_open():
try:
oCtx = uno.getComponentContext()
oServiceManager = ctx.getServiceManager()
oFilePicker = oServiceManager.createInstanceWithArgumentsAndContext(
'com.sun.star.ui.dialogs.OfficeFilePicker',
(FILEOPEN_SIMPLE,),
oCtx
)
oFilePicker.Title = 'Open as'
#oDisp = oFilePicker.Text
oFilePicker.execute()
except:
pass
#oDisp = traceback.format_exc(sys.exc_info()[2])
file_dialog_open
but I got this error:
com.sun.star.uno.RuntimeExceptionError during invoking function file_dialog_open in module file:///C:/Program%20Files/LibreOffice%205/share/Scripts/python/pythonSamples/TesteRomana.py (<class 'TypeError'>: file_dialog_open() takes 0 positional arguments but 1 was given
C:\Program Files\LibreOffice 5\program\pythonscript.py:870 in function invoke() [ret = self.func( *args )]
)