Filling form

Fill a form with the data stored in the object:

  • open an existing form document and get all forms (ApiDocument/GetAllForms);
  • run a loop for each form, check the form type and set the data corresponding to the form key (ApiFormBase/GetFormType, ApiFormBase/GetFormKey, ApiPictureForm/SetImage, ApiComboBoxForm/SetText)

This sample is available for the C++ and .Net DocBuilder Frameworks. Download the sample and get more information on the Builder framework samples page.

const oDocument = Api.GetDocument()

const data = {
  "Photo": "https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png",
  "Serial": "A1345",
  "Company Name": "ONLYOFFICE",
  "Date": "25.12.2023",
  "Recipient": "Space Corporation",
  "Qty1": "25",
  "Description1": "Frame",
  "Qty2": "2",
  "Description2": "Stack",
  "Qty3": "34",
  "Description3": "Shifter",
}

const aForms = oDocument.GetAllForms()
for (const form of aForms) {
  if (form.GetFormType() === "textForm") {
    form.SetText(data[form.GetFormKey()])
  }
  if (form.GetFormType() === "pictureForm") {
    form.SetImage(data[form.GetFormKey()])
  }
}

Api.Save()

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).