To automate the manipulation of documents within our applications we need some reliable APIs. The market offers both Open Source Software (OSS) and Closed Source Softwares (CSS) to work with Word Processing Documents. Closed source APIs are often costly. There are a bunch of free APIs available with both basic and advanced features, following are a few of them:

Getting Started with Free APIs

Let’s get started with the installation and basic usage of APIs.

Open XML SDK

Open XML SDK requires .NET Framework 3.5 or above. You can install the library from NuGet using the following command.

Install-Package DocumentFormat.OpenXml

After you are done with the installation, you can create a simple DOCX document free using the following code.

// Open an existing word processing document
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open("fileformat.docx", true))
{
    Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
    // Add paragraph
    Paragraph para = body.AppendChild(new Paragraph());
    Run run = para.AppendChild(new Run());
    run.AppendChild(new Text("File Format Developer Guide"));
}

For details please visit this link.

NPOI

NPOI is a .NET version of the POI Java Project. Just like Open XML SDK, you can install in using NuGet.

Install-Package NPOI -Version 2.4.1

Similarly, creating a document with NPOI is even simpler. You can create a DOCX file using a few lines of code.

using (FileStream sw = File.Create("fileformat.docx"))
{
    XWPFDocument doc = new XWPFDocument();
    doc.CreateParagraph();
    doc.Write(sw);
}

For details please visit this link.

Openize.Words for .NET

Using Openize.Words for .NET, you can manipulate Word 2007/2010/2013 files easily. To get started with Openize.Words for .NET, you can install it using.

Install-Package Openize.Words

Like Open XML SDK & NPOI, creating a document with DocX is pretty simple

using (var doc = new Openize.Words.Document())
            {
                // body of the word document
                var body = new Openize.Words.Body(doc);
                // word document paragraph
                var para = new Openize.Words.IElements.Paragraph();
                // add text to the paragraph and define font
                para.AddRun(new Openize.Words.IElements.Run
                { Text = "File Format Developer Guide" , FontFamily = "Arial Black" });
                // append paragraph to the word document body
                body.AppendChild(para);
                // save word document to disk
                doc.Save("fileformat.docx");
            }

For details please visit this link.