You already asked this question and I answered at
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/a905cfce-714b-433e-92f4-dc4d43ddb64e 1st october.
Why don't you track your old post?
If my solution didn't work you can tell which part didn't work or what's the problem.
However here is my answer again.
Lets assume you have a word file which likes this. and named Template.docx.
Hi <%Name%>
This is a sample text.
Here is the text : <%Text%>
static void Main(string[] args)
{
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("<%Name%>", "Tamer");
d.Add("<%Text%>", "This is the text in my software");
GenerateWord(@"C:\users\Tamer\Desktop\template.docx", @"C:\users\Tamer\Desktop\generated.docx", d);
}
protected static void GenerateWord(string templateFile, string newFile, Dictionary<string, string> replacements)
{
if (File.Exists(templateFile))
{
Microsoft.Office.Interop.Word.Application my_Word = new Microsoft.Office.Interop.Word.Application();
my_Word.Visible = false;
object oTrue = true;
object oAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
object oFalse = false;
object oMissing = System.Reflection.Missing.Value;
object oLoc = templateFile;
object oNewFile = newFile;
Microsoft.Office.Interop.Word.Document my_Document = (Microsoft.Office.Interop.Word.Document)my_Word.Documents.Open(ref oLoc, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
foreach (KeyValuePair<string, string> kvp in replacements)
{
my_Word.Selection.Find.Replacement.ClearFormatting();
my_Word.Selection.Find.ClearFormatting();
my_Word.Selection.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
object oFindText = kvp.Key;
object oReplaceText = kvp.Value;
my_Word.Selection.Find.Execute(ref oFindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrue, ref oMissing, ref oTrue, ref oReplaceText, ref oAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
my_Document.SaveAs(ref oNewFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
my_Document.Close(ref oTrue, ref oMissing, ref oMissing);
my_Word.Quit(ref oTrue, ref oMissing, ref oMissing);
}
}
In this document <%Name%> means that this will be changed to something else.
And here is the method which will do your Job. You have to add Microsoft.Office.Interop as a reference to your project.