How To Create a Word Document using Spire.Doc
Creating Word documents using .Net is always one of the tedious tasks. Today, in this post, we will see how can we create word documents using Spire.Doc library with ease. You can download the Spire.Doc library from here. Spire.Doc is present in Community as well as Commercial edition. You can use the community edition for reading/writing 100 paragraphas and 5 tables only. If your content is more than this, you will need to purchase the commercial edition.
To generate Word documents, you don’t need MS Office installed on your machine. Without wasting time, let us see how can we use this awesome product to create word documents on the fly. To write any word document, you need to follow the 4 basic steps –
- Create a new Document or load an existing Document
- Create a new Section
- Create a new paragraph/Table/Picture
- Save the Document
Code to create a new Word Document named Sample.docx and write a piece of content to the file:
//Create word document Document document = new Document(); //Create a new secition Section section = document.AddSection(); //Create a new paragraph Paragraph paragraph = section.AddParagraph(); //Append Text paragraph.AppendText("Writing my first Word document using Spire.Doc!"); //Save doc file. document.SaveToFile("Sample.docx",FileFormat.Docx);
When you run the code, you will see a word file being created as below –
Hope you like this. Keep learning and sharing! Cheers!