Skip to content

Commit 75e9fde

Browse files
committed
Modified the code snippet
1 parent ecae4f2 commit 75e9fde

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Mail-Merge/Insert-hyperlink-during-Mailmerge/.NET/Insert-hyperlink-during-Mailmerge/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public static void Main(string[] args)
88
{
99
// Open the template Word document
1010
WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx"));
11-
// Subscribe to the MailMerge.MergeField event
12-
// This event is triggered whenever a merge field is processed during mail merge
11+
// Attach the event handler that runs when a merge field is processed
1312
document.MailMerge.MergeField += MailMerge_MergeField;
1413
// Define the merge field names present in the template document
1514
string[] fieldNames = new string[] { "EmployeeId", "Name", "Phone", "City", "Contact" };
@@ -19,6 +18,8 @@ public static void Main(string[] args)
1918
document.MailMerge.Execute(fieldNames, fieldValues);
2019
// Save the result document
2120
document.Save(Path.GetFullPath(@"../../../Output/output.docx"));
21+
// Close the Word document
22+
document.Close();
2223
}
2324
/// <summary>
2425
/// Event handler that customizes how merge fields are processed.

0 commit comments

Comments
 (0)