Skip to content

change_formfieldvalue

Jochen Staerk edited this page Dec 21, 2015 · 1 revision

Source: Markus Krüger (NOA developer)

The following code shows how to change the value of OpenOffice.org form text fields:

  ...
  ITextDocument textDocument = ...;
  IFormComponent[] formComponents = textDocument.getFormService().getFormComponents();
  for (int i = 0; i < formComponents.length; i++) {
    XFormComponent xFormComponent = formComponents[i].getXFormComponent();
    XTextComponent xTextComponent = formComponents[i].getXTextComponent();
    XPropertySet propertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
        xFormComponent);
    if (propertySet != null && propertySet.getPropertySetInfo().hasPropertyByName("Name")) {
      String name = propertySet.getPropertyValue("Name").toString();
      if (name.equalsIgnoreCase("TextBoxForename")) {
        xTextComponent.setText("My new forename");
      }
      else if (name.equalsIgnoreCase("TextBoxSurname")) {
        xTextComponent.setText("My new surname");
      }
    }
  }
Clone this wiki locally