How to Create Word Document in C# without Interop

Some People use Microsoft Office Interop library to create Word documents, however they often ask the question how to create Word document in C# without interop. This is where Aspose.Words for .NET comes into play to help create Word document in C# easily.

This question is being answered in the below steps along with the C# code sample. This shows how easily and efficiently you can create DOCX or DOC file from scratch in your .NET applications, be it a .NET console utility, Windows application, or ASP.NET web project. Aspose.Words seamlessly work with every .NET platform technology.

Steps to Create Word Document in C# without Automation

  1. Use Aspose.Words for .NET NuGet package
  2. Add reference to Aspose.Words namespace
  3. Use SetLicense method to apply Aspose license
  4. Create a new Document Class instance
  5. Create a DocumentBuilder Class object and pass Document object in the constructor
  6. Set required properties of the DocumentBuilder object
  7. Save the output Word document as a file or a stream

Code to Create Word Document in C# without Automation

In this C# code example, we created a simple Word document with just two lines of text and applied bold attribute to the text. However, you can do a lot more and expand above code by adding tables, cells, and different other objects of the Word Document Object Model (DOM).

To execute above C# code of Aspose.Words for .NET API, you’re not required to install Microsoft Word on your computer or the server where application will be installed. This makes creating word document a lot easier and quicker.

 English