FJCC wrote:There may be a better way but this seems to do the job.
Code: Select all
oTextFields = ThisComponent.getTextFields()
Enum = oTextFields.createEnumeration()
While Enum.hasMoreElements()
oField = Enum.nextElement()
If oField.TextFieldMaster.Name = "ClientName" Then
oField.TextFieldMaster.Content = "John Smith"
End If
Wend
There is a better way - you can call each field by name using the TextFieldMasters property of the document as described here:
https://www.openoffice.org/api/docs/com ... sters.html
the TextFieldMasters property is a collection that implements the XNameAccess interface (which means you can use the
method to retrieve the instance then set the value with a method like the following:
Code: Select all
def set_field(self, document, name, value):
field = document.TextFieldMasters.getByName('com.sun.star.text.fieldmaster.User.{0}'.format(name))
field.Content = value
note that the name of the text field needs to include the namespace (hence the string formatting). If you keep getting
s, you can use the following code to print out the contents of the collection:
Code: Select all
for field_name in document.TextFieldMasters.getElementNames():
print(field_name)