using docbuilder_net; using OfficeFileTypes = docbuilder_net.FileTypes; using CValue = docbuilder_net.CDocBuilderValue; using CContext = docbuilder_net.CDocBuilderContext; using CContextScope = docbuilder_net.CDocBuilderContextScope; namespace Test { public class Program { public static void Main(string[] args) { string workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder"; string resultPath = "result.docx"; // add Docbuilder dlls in path System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + workDirectory); Test(workDirectory, resultPath); // uncomment to check finalizer calls // GC.Collect(); // Console.ReadKey(); } public static void Test(string workDirectory, string resultPath) { var doctype = (int)OfficeFileTypes.Document.DOCX; CDocBuilder.Initialize(workDirectory); CDocBuilder oBuilder = new CDocBuilder(); oBuilder.CreateFile(doctype); CContext oContext = oBuilder.GetContext(); CContextScope oScope = oContext.CreateScope(); CValue oGlobal = oContext.GetGlobal(); CValue oApi = oGlobal["Api"]; CValue oDocument = oApi.Call("GetDocument"); CValue oParagraph1 = oApi.Call("CreateParagraph"); oParagraph1.Call("SetSpacingAfter", 1000, false); oParagraph1.Call("AddText", "Hello from .net!"); CValue oParagraph2 = oApi.Call("CreateParagraph"); oParagraph2.Call("AddText", "Goodbye!"); CValue oContent = new CValue[] { oParagraph1, oParagraph2 }; oDocument.Call("InsertContent", oContent); oBuilder.SaveFile(doctype, resultPath); oBuilder.CloseFile(); CDocBuilder.Destroy(); } } }