Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-kb/aa2b32cb1fbde76e43a550353d1dc8f5 to your computer and use it in GitHub Desktop.
Save aspose-com-kb/aa2b32cb1fbde76e43a550353d1dc8f5 to your computer and use it in GitHub Desktop.
Create Word Document in C# without Interop. The code in this gist along with how to use this code is explained in the topic https://kb.aspose.com/words/net/how-to-create-word-document-in-c-sharp-without-interop/.
using System;
//Add reference to Aspose.Words for .NET API
//Use following namespaces to Word Document generator code
using Aspose.Words;
namespace CreateWordDocumentWithoutInterop
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before creating Word document without Interop
//using Aspose.Words for .NET
Aspose.Words.License AsposeWordsLicense = new Aspose.Words.License();
AsposeWordsLicense.SetLicense(@"c:\asposelicense\license.lic");
//Create an instance of Document class of Aspose.Words for .NET
//This initiates a blank Word document
Document WordDocumentWithoutInterop = new Document();
//An instance of DocumentBuilder class is used to add
//content to the Word Document
DocumentBuilder WordDocumentBuilder = new DocumentBuilder(WordDocumentWithoutInterop);
//Add some text with bold formatting
WordDocumentBuilder.Bold = true;
WordDocumentBuilder.Writeln("We're adding this line of text in the word document using DocumentBuilder Class");
WordDocumentBuilder.Writeln("This does not require Office Interop or Office Automation");
//Finally, save the generated word document to docx format
WordDocumentWithoutInterop.Save("Word_Document_Created_Without_Interop_using_CSharp.docx");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment