We will create a Windows application to demonstrate how to generate a Word doc as a report (Certificate) using the Spire.net library.
Spire.Doc for .NET is a library for developers to create, read, write, convert, and print Word document files from C#, VB.NET, and ASP.NET with quality performance.
Step 1. Create Windows Form Application, go to File - New Project, Windows, then Windows Forms Application, give the name 'WinSpiredoc', and click 'Ok'.
This will create a Windows form application as in the following screenshot.
![Windows]()
Step 2. Create a layout by drag and drop the Button control on the form.
![Create a layout]()
Step 3. Change the button text property and give the name 'Generate Certificate'.
![Generate Certificate]()
Step 4. Add the reference dll of Spire.Doc.dll in your project, this is the dll using the class and methods we are going to generate a Word document.
![Word document]()
Step 5. Include Spire.Doc and Spire.Doc.Document reference in your Form. cs file. For downloading and using Spire.Doc please click here.
![Document reference]()
Step 6. Now add the following code on your button click event. Here we are creating a document object, and for that load a document first, then we will append the text paragraph, and lastly we will save the doc file and launch the MS Word file.
private void button1_Click(object sender, EventArgs e)
{
// Create word document
Document document = new Document();
// Load a document
document.LoadFromFile(@"D:\Ankur\PROJECTS\My Blogs\certificate.txt");
// Get a paragraph
Paragraph paragraph = document.Sections[0].AddParagraph();
// Append Text
paragraph.AppendText("This is to certify that Mr / Ms._____________________, has successfully completed his ______________________________ study with specialisation in _____________ at XYZ University.");
// Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
// Launching the MS Word file.
WordDocViewer("Sample.doc");
}
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
Step 7. Now run the application and click on the 'Generate Certificate' Button.
![Certificate]()
Step 8. This will open a Word doc file with the paragraph you have added to the code.
![Word doc]()
You can create invoices, certificates, bills, etc, dynamically using this without utilizing Microsoft Word.
So, using Spire.Doc, you can generate, modify, convert, render, and print documents without utilizing Microsoft Word®.
But you need MS Word viewer to view the resultant document.
Hope you like this article.