PUUUUUU
PUUUUUU

Reputation: 11

How to insert text into onlyoffice webword?

I want to insert text into word, but I can not find the api;

let docEditor = new DocsAPI.DocEditor("placeholder", config);

docEditor.insertText('simple text') // this is I want to do, but insertText is undefine

Upvotes: 1

Views: 394

Answers (2)

luigisuncorner
luigisuncorner

Reputation: 380

If you want to insert text with OnlyOffice DocumentServer from the web view, you need to use the "Automation API" (see https://api.onlyoffice.com/editors/connector). It's not free though, neither in the open-source version nor in the Developer Edition trial.

Load the Automation API like this:

var docEditor = new DocsAPI.DocEditor("placeholder", config);
var connector = docEditor.createConnector();

and then the connector object exposes the method callCommand, which allows you to execute the Text document API functions to edit/insert text (example from here):

connector.callCommand(function() {
    var oDocument = Api.GetDocument();
    var oParagraph = Api.CreateParagraph();
    oParagraph.AddText(Asc.scope.text);
    oDocument.InsertContent([oParagraph]);
}, function() { console.log("callback command"); });

So the other answer just explained the code for the Text document API, but not how you access it. This is done through the connector ("Automation API"), which is not free. From the official forum (see here): "Document Server is capable of listening for the data from external sources only with Developer Edition license".

Upvotes: 0

probelover
probelover

Reputation: 9

You can read this url https://api.onlyoffice.com/docbuilder/textdocumentapi
sample code:

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is just a sample text. Nothing special.");
builder.SaveFile("docx", "AddText.docx");
builder.CloseFile();

Upvotes: 0

Related Questions