window.Asc.plugin.executeCommand(type, command)

Description

Used to send the data back to the editor. This method is mainly used to work with the OLE objects and is retained for using with text so that the previous versions of the plugin remain compatible.

The second parameter is the JavaScript code for working with ONLYOFFICE Document Builder API that allows the plugin to send structured data inserted to the resulting document file (formatted paragraphs, tables, text parts and separate words, etc.).

NB:
ONLYOFFICE Document Builder commands can be only used to create content and insert it to the document editor (using the Api.GetDocument().InsertContent(...)). This limitation exists due to the co-editing feature in the online editors. If it is necessary to create a plugin for the desktop editors to work with local files, no such limitation is applied.
Parameters
Name Description Type
type Defines the type of the command. The "close" is used to close the plugin window after executing the function in the command parameter. The "command" is used to execute the command and leave the window open waiting for the next command. string
command Defines the command written in JavaScript code whose purpose is to form the structured data which can be inserted to the resulting document file (formatted paragraphs, tables, text parts and separate words, etc.). Then the data is sent to the editors. The command must be compatible with ONLYOFFICE Document Builder syntax. string

When creating/editing OLE objects, two extensions are used to work with them:

  • Api.asc_addOleObject(window.Asc.plugin.info) - used to create an OLE object in the document;
  • Api.asc_editOleObject(window.Asc.plugin.info) - used to edit the created OLE object.

When creating/editing the objects, their properties can be passed to the window.Asc.plugin.info object that defines how the object should look.

Example OLE object
window.Asc.plugin.button = function (id) {
    var _info = window.Asc.plugin.info;
    var _method = (_info.objectId === undefined) ? "asc_addOleObject" : "asc_editOleObject";
    _info.width = _info.width ? _info.width : 70;
    _info.height = _info.height ? _info.height : 70;
    _info.widthPix = (_info.mmToPx * _info.width) >> 0;
    _info.heightPix = (_info.mmToPx * _info.height) >> 0;
    _info.imgSrc = window.g_board.getResult(_info.widthPix, _info.heightPix).image;
    _info.data = window.g_board.getData();
    var _code = "Api." + _method + "(" + JSON.stringify(_info) + ");";
    this.executeCommand("close", _code);
};
Example text (not used but retained for compatibility reason)
window.Asc.plugin.init = function () {
    var sScript = 'var oDocument = Api.GetDocument();';
    sScript += 'oDocument.CreateNewHistoryPoint();';
    sScript += 'oParagraph = Api.CreateParagraph();';
    sScript += 'oParagraph.AddText(\'Hello word!\');';
    sScript += 'oDocument.InsertContent([oParagraph]);';
    window.Asc.plugin.info.recalculate = true;
    this.executeCommand("close", sScript);
};