Well,
you can [spam link removed] file programatically, but what you really should be doing is [spam link removed] Word file with DataTable from your database.
Here is a sample C# code how to accomplish this with [spam link removed] component:
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var dataTable = new DataTable("People")
{
Columns =
{
new DataColumn("Name", typeof(string)),
new DataColumn("Surname", typeof(string))
},
Rows =
{
new object[] { "John", "Doe" },
new object[] { "Fred", "Nurk" },
new object[] { "Hans", "Meier" },
new object[] { "Ivan", "Horvat" }
}
};
var document = new DocumentModel();
document.Sections.Add(
new Section(document,
new Table(document,
new TableRow(document,
new TableCell(document,
new Paragraph(document, "Name")),
new TableCell(document,
new Paragraph(document, "Surname"))),
new TableRow(document,
new TableCell(document,
new Paragraph(document,
new Field(document, FieldType.MergeField, "RangeStart:People"),
new Field(document, FieldType.MergeField, "Name"))),
new TableCell(document,
new Paragraph(document,
new Field(document, FieldType.MergeField, "Surname"),
new Field(document, FieldType.MergeField, "RangeEnd:People")))))));
document.Save("TemplateDocument.docx", SaveOptions.DocxDefault);
document = DocumentModel.Load("TemplateDocument.docx", LoadOptions.DocxDefault);
document.MailMerge.ExecuteRange(dataTable);
document.Save("Document.docx", SaveOptions.DocxDefault);