1

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
1
  • 2
    Listing 5.49 in Section 5.18.3 on page 64 of Andrew Pitonyak's Useful Macro Information For OpenOffice.org shows a simple example of programmatically changing the text in a field, albeit in OOo Basic. Should be straightforward to translate to Python. If you happen not to have a copy of this document, it's available from his very turn-of-the-century OpenOffice.org Macro Information webpage as PDF or ODT along with a lot of other macro info, or as ODT directly from pitonyak.org/AndrewMacro.odt. Commented Aug 14 at 13:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.