Three Open-Source .NET APIs for Word Processing Documents

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.

DocX

Using DocX you can manipulate Word 2007/2010/2013 files easily. To get started with DocX you can install it using.

Install-Package DocX -Version 1.5.0

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

using (DocX document = DocX.Create("fileformat.docx"))
{
    // Add a new Paragraph to the document.
    Paragraph pagagraph = document.InsertParagraph();
    // Append some text.
    pagagraph.Append("File Format Developer Guide").Font("Arial Black");
    // Save the document.
    document.Save();
}

For details please visit this link.