I'm new at using python with the LibreOffice suite. I'm basically trying to programmatically copy a base Impress file and mass copy it but changing the size of certain text boxes.
I checked some documentation online about this but was confused on how to actually achieve it.
Thank you
Edit: I wrote this test code
import os
import zipfile
import glob
import uno
def MassCreatePresentation():
file = os.path.abspath(glob.glob('INTROTEMPLATE.pptx')[0])
print('File Found')
print(file)
oDoc = XSCRIPTCONTEXT.getDocument()
return
But it shows this error:
File "MassPresentation.py", line 10, in MassCreatePresentation
oDoc = XSCRIPTCONTEXT.getDocument()
NameError: name 'XSCRIPTCONTEXT' is not defined
Edit:
Ok I finally figured this out using this logic. The way I did it:
1)get shutil to copy base file 2)use zipfile to unzip the copied pptx file, 3)navigate to the slide xml and use readlines() 4)modify the xml and save it 5)archive as zip and then rename file to .pptx 6)Celebrate
Since macro recording does not seem possible in Impress, there might be another way that you could try.
LibreOffice files are basically just zip-files with xml or image files in it.
If you unzip the odp-file there is a
content.xml
inside.You could process this file using ElementTree or lxml and change the field you need. The font setting are also somewhere in there.
I could not find a good documentation which methods are available using the macro iterface. It might be more elegant, but doing it like this is rather proven to work within one or two hours of work:
This page shows some codes to work with zip and LibreOffice files. Also this one.
At best put the content of
content.xml
through an online formatter like this. So can get a good idea on its structure.You can assign the font directly or be using one of the defined styles.
This is the definition of
L1
:within
<office:automatic-styles>
This is the usage of that stype:
There is only very little information and examples around regarding Impress macros and most of them are in BASIC: