ONLYOFFICE macros

In ONLYOFFICE editors macros are small scripts used to facilitate your day-to-day routine work with different types of documents. Macros use JavaScript language syntax and ONLYOFFICE Document Builder API scripting notation, thus the methods available in JavaScript and all the methods supported by ONLYOFFICE Document Builder are also supported by macros.

You can add your own macros to documents (all document types are supported: text, spreadsheet, presentation), edit, save them with the document - anything to make your work with document files easier and more convenient.

Getting started with macros

Macro is a JavaScript function linked with a document. The simplest function which will insert the "Hello world!" phrase into the text document when run, will look like this:

(function()
{
    var oDocument = Api.GetDocument();
    var oParagraph = Api.CreateParagraph();
    oParagraph.AddText("Hello world!");
    oDocument.InsertContent([oParagraph]);
})();

In the desktop editor interface this will look the following way:

Macros window

To access macros, open or create a document of the necessary type, click the Plugin button plugin button and select Macros. The macros window will be opened. Click New and enter your script code into the right-side window. When ready, click Run to run your code onto the document.

That's it, really easy.

You can also rename your macro, to distinguish it from the other ones in case they are used in the same document, or delete the unnecessary ones.