Hi All,
Currently I have a requirement which is follows:
I have a word template which contains some text information and with some fields like "ADDRESS" and "DATE" "NAME" in the word templates.
I have developed a Windows forms application with C#.Net and SQL Server Database. The windows forms application contains the navigation buttons like "FIRST","NEXT","LAST","PREVIOUS". and a button called PRINT as well as some text boxes to show the records in the database while navigating.
Whenever user clicks PRINT button it have to take a word template from a shred folder and it will update all the above said fields which are available in the WORD document with the current record details. This is some thing like MAIL MERGE activity.
Please help me to resolve the issue. And also please possible solutions in order to fulfill my requirement.
Thanks in Advance
Balaji Yerukola
Loading
Suthish NairPosted Feb 19, 2012, 1:36 PM
John GlennPosted Mar 2, 2012, 5:36 AM
if you are working on DOCX in C#, then you can try this C# / VB.NET Word component.
Here is a sample .NET Word mail merge code:
var dataTable = new DataTable()
{
Columns =
{
new DataColumn("Date", typeof(string)),
new DataColumn("Address", typeof(string)),
new DataColumn("Name", typeof(string))
},
Rows =
{
new object[] { DateTime.Now.ToShortDateString(), "New York", "John Doe" },
new object[] { DateTime.Now.ToShortDateString(), "Washington", "Fred Nurk" },
new object[] { DateTime.Now.ToShortDateString(), "San Francisco", "Hans Meier" }
}
};
// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create a template document for demonstration purpose.
var document = new DocumentModel();
document.Sections.Add(
new Section(document,
new Paragraph(document,
new Run(document, "Date: "),
new Field(document, FieldType.MergeField, "Date"),
new SpecialCharacter(document, SpecialCharacterType.LineBreak),
new Run(document, "Address: "),
new Field(document, FieldType.MergeField, "Address"),
new SpecialCharacter(document, SpecialCharacterType.LineBreak),
new Run(document, "Name: "),
new Field(document, FieldType.MergeField, "Name"))));
// Load template document from the file.
// var document = DocumentModel.Load("TemplateDocument.docx", LoadOptions.DocxDefault);
// Merge template document with the first row from the DataTable.
document.MailMerge.Execute(dataTable.Rows[0]);
// Save the document to a file.
document.Save("Document.docx", SaveOptions.DocxDefault);