Create Word Document programatically with Docx in C#

Docx is an opensource library which provide creation and manipulation of Microsoft Word Document. It is one of of the easiest way to create documents in your C# application. Above all no need to install Office word on your system and it is fast.

DocX is best alterate for Office.Interop.Word which require Office Installation in your system.

The developer made a good and fruitfull effort to deliver such a fast library, thanks lot

First you need to add the library to your project and using it. Use Nuget Package Manager to add the Library for that.

using Xceed.Document.NET;

Now you can create you document with Docx. Create method will perform file operation adfter you called the Save. Here is the sample code

string fileName=@"/doc/sample.docx";
using (var document = DocX.Create(fileName))
                    // Add a title
                    document.InsertParagraph("This is Sample Text").FontSize(15d).SpacingAfter(50d).Alignment =;
document.InsertParagraph("This is last line of this Document");

You can also work on tables,List and styles as you do on Word Application. Docx is faster than Interop.Word

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

One thought on “Create Word Document programatically with Docx in C#”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.