diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.sln b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.sln new file mode 100644 index 00000000..8867d8ef --- /dev/null +++ b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37531.7 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply-Bullet-List-Formatting-To-Mail-Merge-Fields", "Apply-Bullet-List-Formatting-To-Mail-Merge-Fields\Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.csproj", "{FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB00AB02-CAE5-C3C9-12C3-2FA1206F13D0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B51C4AB2-0F01-4F3D-92E9-3EA8F7615BFC} + EndGlobalSection +EndGlobal diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.csproj b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.csproj new file mode 100644 index 00000000..d4168c56 --- /dev/null +++ b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Replacing_MergeField_With_Bullet_List + + + + + Always + + + Always + + + + + + + + + + diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Data/Template.docx b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Data/Template.docx new file mode 100644 index 00000000..fccf4a77 Binary files /dev/null and b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Data/Template.docx differ diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/.gitkeep b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/Output.docx b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/Output.docx new file mode 100644 index 00000000..445a3a0c Binary files /dev/null and b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Output/Output.docx differ diff --git a/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Program.cs b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Program.cs new file mode 100644 index 00000000..8b4f7c07 --- /dev/null +++ b/Mail-Merge/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/.NET/Apply-Bullet-List-Formatting-To-Mail-Merge-Fields/Program.cs @@ -0,0 +1,47 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; + +namespace Replacing_MergeField_With_Bullet_List +{ + class Program + { + static void Main(string[] args) + { + // Loads existing Word document + using (WordDocument wordDocument = new WordDocument(Path.GetFullPath(@"Data/Template.docx"))) + { + string[] fieldNames = { "ContactName", "CompanyName" }; + string[] fieldValues = { "Nancy", "Syncfusion" }; + + // Uses mail merge events to perform formatting during runtime + wordDocument.MailMerge.MergeField += new MergeFieldEventHandler(ApplyListFormat); + + // Performs mail merge + wordDocument.MailMerge.Execute(fieldNames, fieldValues); + + // Saves Word document + wordDocument.Save(Path.GetFullPath(@"Output/Output.docx")); + } + } + + /// + /// Applies the default bullet list formatting to the paragraph + /// that contains the current mail merge field. + /// + /// The source of the mail merge event. + /// + /// Contains data related to the current merge field, including + /// the merge field and its owner paragraph. + /// + private static void ApplyListFormat(object sender, MergeFieldEventArgs args) + { + // Gets the owner paragraph of the current merge field + WParagraph paragraph = args.CurrentMergeField.OwnerParagraph; + + // Applies bullet list style to the paragraph + paragraph.ListFormat.ApplyDefBulletStyle(); + } + + } +} \ No newline at end of file