word using C#
how to create a Word document using C# ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
saurabh mittalPosted Apr 23, 2014, 3:45 AM
Refer to this link.may be it will help u
http://www.c-sharpcorner.com/UploadFile/muralidharan.d/how-to-create-word-document-using-C-Sharp/
Lorine ApplebyPosted Jan 8, 2015, 4:22 AM
Hi mackie, first regarding this line:
// Just to kill WINWORD.EXE if it is running
killprocess("winword");
Don't do that, I believe the reason why you are using it because you noticed that after you run your application a MS Word is still running. This occurs because of the inappropriate closing of that application, you see when working with word automation in C# you need to be careful about correctly releasing those COM resources, for example something link the following should work:
aDoc.Close();
wordApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
But if you want to avoid that hassle with COM interface I would recommend you to try out this C# component for Word documents. You see you can easily read, modify and then write your DOCX files in C# with it.
Also you even have a direct solution for your requirement, instead of using a find and replace approach you should take a look at a mail merging process in C#.
And last thing you even have a direct API for printing your Word documents in C#.
mackie duenasPosted Apr 23, 2014, 10:25 PM
using System;
mackie duenasPosted Apr 23, 2014, 4:51 AM
mackie duenasPosted Apr 23, 2014, 4:50 AM
Farhan ShariffPosted Apr 23, 2014, 3:43 AM
using System.IO;
using Word = Microsoft.Office.Interop.Word;
wordApp.Visible = false;
Word.Document doc = wordApp.Documents.Add();
string dirPath = @"C:\";
//You might want to add some more code here for inserting pages text adding header and footer
doc.Close();
wordApp.Quit();
MessageBox.Show("Word file created");
}