In your case you can use either Mail Merge or LINQ Reporting Engine.
In case of using Mail Merge, you should insert merge fields where values must be inserted. Your template will look like the following:
Then you can use the following simple code to fill your document with data:
Document doc = new Document(@"C:\Temp\in.docx");
string[] fieldNames = new string[] { "EmpID", "EmpName" };
string[] fieldValues = new string[] { "007", "James Bond" };
doc.MailMerge.Execute(fieldNames, fieldValues);
doc.Save(@"C:\Temp\out.docx");
In case of using LINQ Reporting Engine, instead of MS Word merge fields, you should use specials syntax. The template should look like this:
And the following code to fill the template with data:
// In LINQ Reporting Engine you can use variouse data sources,
// For demonstraction purposes use JSON.
string json = "{ \"EmpID\" : \"007\", \"EmpName\" : \"James Bond\" }";
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
JsonDataSource dataSource = new JsonDataSource(new MemoryStream(Encoding.UTF8.GetBytes(json)));
engine.BuildReport(doc, dataSource);
doc.Save(@"C:\Temp\out.docx");
As alternative not traditional solutions you can also use text placeholders and find/replace feature to replace them with real data or bookmarks as a placeholder for your data.