ONLYOFFICE Document Builder v7.2: JS commands, .Net library, JSON conversion, OLE object methods, and more

6 October 2022By Ksenija

We considerably enhanced the Doc Builder API by upgrading wrappers, adding conversion to and from JSON, more options for working with OLE objects, forms, Word Art, charts and tables. Learn all the details below.

ONLYOFFICE Document Builder v7.2: JS commands, .Net library, JSON conversion, OLE object methods, and more

Completely optimized

We fully upgraded the native ONLYOFFICE Doc Builder API to make document generation more comfortable using JS commands instead of text ones.

The integration API includes new classes and methods which make it easier to work with С/С++ data types.

CValue oApi = oGlobal["Api"]; 
CValue oDocument = oApi.Call("GetDocument"); 
CValue oParagraph = oApi.Call("CreateParagraph"); 
oParagraph.Call("SetSpacingAfter", 1000, false); 
oParagraph.Call("AddText", "Hello, world!"); 
CValue oContent = oContext.CreateArray(1); 
oContent[0] = oParagraph; 
oDocument.Call("InsertContent", oContent);

Moreover, we added the .Net doctrenderer library which allows working with the Doc Builder API in your .Net-based app. We are also going to add the Java wrapper option a bit later.

JSON conversion

With the new FromJSON and ToJSON methods, you can convert the specified JSON object into the Document Builder object of the corresponding type and vice versa — convert the ApiDocument object into the JSON object. This applies to such elements as hyperlinks, paragraphs, numberings, tables, slides, etc.

var oDocument = Api.GetDocument();
var sJSON = oDocument.ToJSON(false, false, true, true);
builder.SaveFile("docx", "ToJSON.docx");

OLE methods

We added the ApiOleObject class to the Doc Builder API. For example, with the CreateOleObject method, you can create an OLE object with the specified parameters. In the practical way, this allows adding and editing spreadsheets as OLE objects embedded in text docs, sheets, and slides what can be useful when working with smart statistics and reports.

var oWorksheet = Api.GetActiveSheet(); 
oWorksheet.AddOleObject("", 130 * 36000, 90 * 36000, "", "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}", 0, 2 * 36000, 4, 3 * 36000); 
builder.SaveFile("xlsx", "AddOleObject.xlsx"); 

New form methods

Thanks to the new form methods, it’s now possible to retrieve a list of all tags which are used for Content Controls and forms in the document, as well as get back a list of all Content Controls and forms with the specified tag name.

It simplifies work with fields in the automatic mode, for example, when parsing a document without opening it.


Endnotes, footnotes, Word Art

Build documents with endnotes and footnotes:

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

Besides, now you can create Word Art objects when generating text documents, spreadsheets, and presentations.

More chart and drawing methods

New chart methods include:

Among updated drawing methods you will find:

  • ReplaceDrawing to replace a drawing with a new one;
  • GetLockValue to get back the lock value for the specified lock type of the current drawing;
  • SetDrawingPrFromDrawing to set the properties from another drawing to the current one;
  • and several others.

Other updates

With the UpdateAllTOC and UpdateAllTOF methods, you are able to update all Tables of Contents and all Tables of Figures in the current document.

New table methods for text docs allow setting/getting the table description and table title/caption.

Explore the full list of new methods with descriptions