[Programming] Create template based documents from remote process

I’m about to write a desktop application where teachers can manage grades and write evaluations about students.

I’d like to use LibreOffice as an engine to create annual reports, containing the calculated grades and evaluations of the students. Schools or teachers have to provide their own template document with fields where to put actual grades and text.

What is the best approach to achieve report generation? I’ve read a lot but came to no conclusion…

  1. use UNO and some kind of automation to control “soffice” process and do all the needed things to come to output documents? (start soffice with --accept=..., open template document, somehow clone it, fill in all the fields, save as new document)

  2. open template document, parse content.xml, manipulate field content, save as new document, zip as .odt

  3. setup a kind of mailmerge and run LibreOffice from command-line and call a macro starting the mailmerge process (don’t know whether this is possible)

  4. do you know another approach?

Note: the application will be written in JavaScript, but it’s no problem to bind to C++ or even call Python or the like.

Though most teachers will run application on Windows, I’d like to provide a solution running on MacOS and Linux as well.