Closed wensimin closed 4 months ago
Hello @wensimin !
Here is a sample code for extracting data from forms via a document builder:
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oTextForm = Api.CreateTextForm({"key": "Personal information", "tip": "Enter your first name", "required": true, "placeholder": "First name", "comb": true, "maxCharacters": 10, "cellWidth": 3, "multiLine": false, "autoFit": false});
var oParagraph = oDocument.GetElement(0);
oParagraph.AddElement(oTextForm);
var oComboBoxForm = Api.CreateComboBoxForm({"key": "Personal information2", "tip": "Choose your country", "required": true, "placeholder": "Country", "editable": false, "autoFit": false, "items": ["Latvia", "USA", "UK"]});
oParagraph.AddLineBreak();
oParagraph.AddElement(oComboBoxForm);
var aForms = oDocument.GetAllForms();
aForms[0].SetText("John Smith");
aForms[1].SelectListValue("USA");
for (let aForm of aForms){
console.log(aForm.GetFormKey());
console.log(aForm.GetText());
}
builder.SaveFile("docx", "GetAllForms.docx");
builder.CloseFile();
this code works correctly on the current version of document builder
You can read more about working with document builder here ONLYOFFICE Document Builder and here Web Document Builder API
Try updating the document builder to a current version.
If the problem recurs, please describe the steps to reproduce in more detail.
Tested on version: 8.0.1.31
This issue was closed due no response.
I'm looking for a way to extract form data in word There is code similar to the following
But it seems to fail silently because of ONLYOFFICE/DocumentServer#2361 Is there any way you can help me, thanks