ONLYOFFICE / DocumentBuilder

ONLYOFFICE Document Builder is powerful text, spreadsheet, presentation and PDF generating tool
https://www.onlyoffice.com/document-builder.aspx
GNU Affero General Public License v3.0
111 stars 56 forks source link

Support for fetch or other http request? #103

Closed wensimin closed 4 months ago

wensimin commented 1 year ago

I'm looking for a way to extract form data in word There is code similar to the following

let oforms = Api.GetDocument().GetAllForms();
let rs = {};
for (let oform of oforms){
    rs[oform.GetFormKey()] = oform.GetText();
}
fetch('http://myserver/document/builder/saveData/key',
{
    headers: {
      'Content-Type': 'application/json'
    },
    method: "POST",
    body: JSON.stringify(rs)
})

But it seems to fail silently because of ONLYOFFICE/DocumentServer#2361 Is there any way you can help me, thanks

l8556 commented 6 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

Rita-Bubnova commented 4 months ago

This issue was closed due no response.