Структура формы

Документ формы имеет точно такую же структуру, что и текстовый документ. Единственным отличием является новый объект формы, размещенный с другими элементами абзаца — строками текста, встроенными элементами управления текстовым содержимым и гиперссылками. Существует четыре типа форм: текстовое поле, поле со списком, флажок и форма изображения.

Создание новой формы документа

Простейший пример документа формы с одной текстовой формой, содержащей текст «Джон Смит», можно создать с помощью Документ Конструктора, используя следующий код:

builder.CreateFile("docxf");                      // create a form document file in the .docxf
var oDocument = Api.GetDocument();                // create a new 'oDocument' variable and get the created text document contents
var oTextForm = Api.CreateTextForm();             // create an empty text form
var oParagraph = oDocument.GetElement(0);         // get the first empty paragraph from the created document
oParagraph.AddElement(oTextForm);                 // add the created text form to the first paragraph
oTextForm.SetText("John Smith");                  // add the "John Smith" text to the text form
builder.SaveFile("docxf", "example.docxf");       // save the resulting form document as a file in the .docxf format with the 'example.docxf' name
builder.CloseFile();                              // close the form document file and finish

Открытие существующей формы документа

Если вы хотите отредактировать уже существующий документ формы, вы можете открыть его с помощью Документ Конструктора, получить его элементы и изменить их так, как вам нужно. Единственным отличием от редактора документов в этом случае будет то, что вам не понадобится этот редактор документов. Документ открывается следующим образом:

builder.OpenFile("https://example.com/myformdocument.docxf");        // use a path to an existing 'myformdocument.docxf' form document file to open
var oDocument = Api.GetDocument();                // create a new 'oDocument' variable and get the created text document contents
var oTextForm = Api.CreateTextForm();             // create an empty text form
var oParagraph = oDocument.GetElement(0);         // get the first empty paragraph from the created document
oParagraph.AddElement(oTextForm);                 // add the created text form to the first paragraph
oTextForm.SetText("John Smith");                  // add the "John Smith" text to the text form
builder.SaveFile("docxf", "example.docxf");       // save the resulting form document as a file in the .docxf format with the 'example.docxf' name
builder.CloseFile();                              // close the form document file and finish

Как видите, вам просто нужно использовать builder.OpenFile(); метод класса CDocBuilder с путем к нужному документу формы в качестве аргумента для его открытия. В приведенном выше примере мы открываем документ myformdocument.docxf, получаем его первый абзац и добавляем в него текстовую форму с текстом «Джон Смит». Точно так же можно изменить любой другой элемент документа формы.

Используйте соответствующие разделы документации по API, чтобы узнать, какие методы позволяют изменять определенные свойства форматирования элементов документа и электронной таблицы.