The goal is to write a Python macro that creates a new Writer document from a form letter template and fills in editable fields to automate repetitive correspondence generation. My problem is that I do not know how to write to these fields through the code.
I've been able to find plenty of examples for part 1 of the requirement, creating the new document:
ui = CreateScriptService("UI")
doc = ui.CreateDocument(templatefile="file:///MY_TEMPLATE.ott")
This successfully creates the new document, which is of type 'SF_Writer', but now need to know the property of that object that will allow access to the fields.
The fields were defined as Input Fields in the variables tab (inspired reddit post User Fields = easy document assembly). If there's a better way to set up the template for automation, I'm open to suggestions. Plan to pull the dynamic text for the fields from a spreadsheet or user entry form, but I haven't gotten that far yet.
Tried using multiple AI tools to generate the correct property/method, but the result is always some version of SF_Writer object has no attribute 'XXX'
- doc.FindField("FIELD_NAME")
- doc.FormFields.items()
- doc.getByName("FIELD_NAME")
- doc.GetText()
- doc.TextFieldMasters.getByName("FIELD_NAME")
Also, investigated the list of Development/Dispatch Commands and saw there is an UpdateField command, but this does not seem to take the correct arguments to specify the field name and new value
LibreOffice Community Version: 25.2.5.2 (X86_64)
Build ID: 520(Build:2)
CPU threads: 8; OS: Linux 6.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded